MDL-66570 admin: Add setting to hide captured cron log output

This commit is contained in:
Andrew Nicols
2019-09-17 14:03:31 +08:00
parent 1c3efe48f8
commit e044c3debe
5 changed files with 27 additions and 6 deletions
+8
View File
@@ -271,6 +271,14 @@ $temp->add(
]
)
);
$temp->add(
new admin_setting_configcheckbox(
'task_logtostdout',
new lang_string('task_logtostdout', 'admin'),
new lang_string('task_logtostdout_desc', 'admin'),
1
)
);
if (\core\task\logmanager::uses_standard_settings()) {
$temp->add(
+2
View File
@@ -1213,6 +1213,8 @@ $string['task_logretention'] = 'Retention period';
$string['task_logretention_desc'] = 'The maximum period that logs should be kept for. This setting interacts with the \'Retain runs\' setting: whichever is reached first will apply';
$string['task_logretainruns'] = 'Retain runs';
$string['task_logretainruns_desc'] = 'The number of runs of each task to retain. This setting interacts with the \'Retention period\' setting: whichever is reached first will apply.';
$string['task_logtostdout'] = 'Display log output';
$string['task_logtostdout_desc'] = 'When jobs are running and the output is captured, whether the captured output should also be displayed as the task runs.';
$string['task_type:adhoc'] = 'Ad hoc';
$string['task_type:scheduled'] = 'Scheduled';
$string['task_result:failed'] = 'Fail';
+13 -2
View File
@@ -76,13 +76,18 @@ class logmanager {
*/
protected static $oblevel = null;
/**
* @var bool Output logged content to screen.
*/
protected static $outputloggedcontent = true;
/**
* Create a new task logger for the specified task, and prepare for logging.
*
* @param \core\task\task_base $task The task being run
*/
public static function start_logging(task_base $task) {
global $DB;
global $CFG, $DB;
if (!self::should_log()) {
return;
@@ -129,6 +134,8 @@ class logmanager {
self::$oblevel = null;
}
self::$outputloggedcontent = !empty($CFG->task_logtostdout);
// Start capturing output.
ob_start([\core\task\logmanager::class, 'add_line'], self::CHUNKSIZE);
}
@@ -336,6 +343,10 @@ class logmanager {
fwrite(self::$fh, $log);
}
return $log;
if (self::$outputloggedcontent) {
return $log;
} else {
return '';
}
}
}
+3 -3
View File
@@ -9090,11 +9090,11 @@ function mtrace($string, $eol="\n", $sleep=0) {
$fn($string, $eol);
return;
} else if (defined('STDOUT') && !PHPUNIT_TEST && !defined('BEHAT_TEST')) {
fwrite(STDOUT, $string.$eol);
// We must explicitly call the add_line function here.
// Uses of fwrite to STDOUT are not picked up by ob_start.
\core\task\logmanager::add_line("{$string}{$eol}");
if ($output = \core\task\logmanager::add_line("{$string}{$eol}")) {
fwrite(STDOUT, $output);
}
} else {
echo $string . $eol;
}
+1 -1
View File
@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2019091300.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2019091700.00; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.