Skip to content

Commit

Permalink
Merge branch 'MDL-66570-master' of git://github.com/andrewnicols/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Sep 26, 2019
2 parents 57054fc + e044c3d commit c2c1cbd
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
8 changes: 8 additions & 0 deletions admin/settings/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,14 @@
]
)
);
$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(
Expand Down
2 changes: 2 additions & 0 deletions lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,8 @@
$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';
Expand Down
15 changes: 13 additions & 2 deletions lib/classes/task/logmanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -129,6 +134,8 @@ public static function start_logging(task_base $task) {
self::$oblevel = null;
}

self::$outputloggedcontent = !empty($CFG->task_logtostdout);

// Start capturing output.
ob_start([\core\task\logmanager::class, 'add_line'], self::CHUNKSIZE);
}
Expand Down Expand Up @@ -336,6 +343,10 @@ public static function add_line(string $log) : string {
fwrite(self::$fh, $log);
}

return $log;
if (self::$outputloggedcontent) {
return $log;
} else {
return '';
}
}
}
6 changes: 3 additions & 3 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

defined('MOODLE_INTERNAL') || die();

$version = 2019092000.01; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2019092000.02; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.

Expand Down

0 comments on commit c2c1cbd

Please sign in to comment.