Improve logs during cron actualization (#2964)

For
https://github.com/FreshRSS/FreshRSS/issues/2952#issuecomment-626218921
And fix a little bug writing logs with the wrong user name
pull/2974/head
Alexandre Alapetite 4 years ago committed by GitHub
parent 65b55d2d58
commit 11dd6e91b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 58
      app/actualize_script.php
  2. 3
      lib/Minz/Log.php

@ -2,17 +2,27 @@
<?php <?php
require(__DIR__ . '/../cli/_cli.php'); require(__DIR__ . '/../cli/_cli.php');
/**
* Writes to FreshRSS admin log, and if it is not already done by default,
* writes to syslog (only if simplepie_syslog_enabled in FreshRSS configuration) and to STDERR
*/
function notice($message) {
Minz_Log::notice($message, ADMIN_LOG);
if (!COPY_LOG_TO_SYSLOG && SIMPLEPIE_SYSLOG_ENABLED) {
syslog(LOG_NOTICE, $message);
}
if (defined('STDERR') && !COPY_SYSLOG_TO_STDERR) {
fwrite(STDERR, $message . "\n"); //Unbuffered
}
}
session_cache_limiter(''); session_cache_limiter('');
ob_implicit_flush(false); ob_implicit_flush(false);
ob_start(); ob_start();
echo 'Results: ', "\n"; //Buffered echo 'Results: ', "\n"; //Buffered
if (defined('STDOUT')) { $begin_date = date_create('now');
$begin_date = date_create('now'); notice('FreshRSS starts feeds actualization at ' . $begin_date->format('c'));
fwrite(STDOUT, 'Starting feed actualization at ' . $begin_date->format('c') . "\n"); //Unbuffered
}
syslog(LOG_INFO, 'FreshRSS Start feeds actualization...');
// Set the header params ($_GET) to call the FRSS application. // Set the header params ($_GET) to call the FRSS application.
$_GET['c'] = 'feed'; $_GET['c'] = 'feed';
@ -25,12 +35,13 @@ $app = new FreshRSS();
$system_conf = Minz_Configuration::get('system'); $system_conf = Minz_Configuration::get('system');
$system_conf->auth_type = 'none'; // avoid necessity to be logged in (not saved!) $system_conf->auth_type = 'none'; // avoid necessity to be logged in (not saved!)
define('SIMPLEPIE_SYSLOG_ENABLED', $system_conf->simplepie_syslog_enabled);
// make sure the PHP setup of the CLI environment is compatible with FreshRSS as well // make sure the PHP setup of the CLI environment is compatible with FreshRSS as well
performRequirementCheck($system_conf->db['type']); performRequirementCheck($system_conf->db['type']);
// Create the list of users to actualize. // Create the list of users to actualize.
// Users are processed in a random order but always start with admin // Users are processed in a random order but always start with default user
$users = listUsers(); $users = listUsers();
shuffle($users); shuffle($users);
if ($system_conf->default_user !== '') { if ($system_conf->default_user !== '') {
@ -43,44 +54,35 @@ $min_last_activity = time() - $limits['max_inactivity'];
foreach ($users as $user) { foreach ($users as $user) {
if (($user !== $system_conf->default_user) && if (($user !== $system_conf->default_user) &&
(FreshRSS_UserDAO::mtime($user) < $min_last_activity)) { (FreshRSS_UserDAO::mtime($user) < $min_last_activity)) {
Minz_Log::notice('FreshRSS skip inactive user ' . $user, ADMIN_LOG); notice('FreshRSS skip inactive user ' . $user);
if (defined('STDOUT')) {
fwrite(STDOUT, 'FreshRSS skip inactive user ' . $user . "\n"); //Unbuffered
}
continue; continue;
} }
Minz_Log::notice('FreshRSS actualize ' . $user, ADMIN_LOG);
if (defined('STDOUT')) {
fwrite(STDOUT, 'Actualize ' . $user . "...\n"); //Unbuffered
}
echo $user, ' '; //Buffered
Minz_Session::_param('currentUser', $user); Minz_Session::_param('currentUser', $user);
new Minz_ModelPdo($user); //TODO: FIXME: Quick-fix while waiting for a better FreshRSS() constructor/init new Minz_ModelPdo($user); //TODO: FIXME: Quick-fix while waiting for a better FreshRSS() constructor/init
FreshRSS_Auth::giveAccess(); FreshRSS_Auth::giveAccess();
$app->init(); $app->init();
notice('FreshRSS actualize ' . $user . '...');
echo $user, ' '; //Buffered
$app->run(); $app->run();
if (!invalidateHttpCache()) { if (!invalidateHttpCache()) {
Minz_Log::warning('FreshRSS write access problem in ' . join_path(USERS_PATH, $user, 'log.txt'), ADMIN_LOG); Minz_Log::warning('FreshRSS write access problem in ' . join_path(USERS_PATH, $user, 'log.txt'), ADMIN_LOG);
if (defined('STDERR')) { if (defined('STDERR')) {
fwrite(STDERR, 'FreshRSS write access problem in ' . join_path(USERS_PATH, $user, 'log.txt') . "\n"); fwrite(STDERR, 'FreshRSS write access problem in ' . join_path(USERS_PATH, $user, 'log.txt') . "\n");
} }
} }
Minz_Session::_param('currentUser', '_');
Minz_Session::_param('loginOk');
gc_collect_cycles(); gc_collect_cycles();
} }
Minz_Log::notice('FreshRSS actualize done.', ADMIN_LOG); $end_date = date_create('now');
if (defined('STDOUT')) { $duration = date_diff($end_date, $begin_date);
fwrite(STDOUT, 'Done.' . "\n"); notice('FreshRSS actualization done for ' . count($users) .
$end_date = date_create('now'); ' users, using ' . format_bytes(memory_get_peak_usage(true)) . ' of memory, in ' .
$duration = date_diff($end_date, $begin_date); $duration->format('%a day(s), %h hour(s), %i minute(s) and %s seconds.'));
fwrite(STDOUT, 'Ending feed actualization at ' . $end_date->format('c') . "\n"); //Unbuffered
fwrite(STDOUT, 'Feed actualizations took ' . $duration->format('%a day(s), %h hour(s), %i minute(s) and %s seconds') . ' for ' . count($users) . " users\n"); //Unbuffered
fwrite(STDOUT, 'Memory usage: ' . format_bytes(memory_get_peak_usage(true)) . "\n"); //Unbuffered
}
echo 'End.', "\n"; echo 'End.', "\n";
ob_end_flush(); ob_end_flush();
syslog(LOG_INFO, 'FreshRSS feeds actualization done.');

@ -55,7 +55,8 @@ class Minz_Log {
$level_label = 'debug'; $level_label = 'debug';
break; break;
default : default :
$level_label = 'unknown'; $level = LOG_INFO;
$level_label = 'info';
} }
$log = '[' . date('r') . ']' $log = '[' . date('r') . ']'

Loading…
Cancel
Save