Add Log to STDOUT Feature (#5721)

Primarily useful for PHP applications running under PHP-FPM which in
turn is running within a Docker container. But also it is generally
useful in any situation where you want to be able to send the logs
directly to your terminal when debugging &etc.
pull/276/merge
Joel Gerber 7 years ago committed by Aleksander Machniak
parent 938dd4670b
commit 40b51b9dc9

@ -66,7 +66,7 @@ $config['db_max_allowed_packet'] = null;
// system error reporting, sum of: 1 = log; 4 = show
$config['debug_level'] = 1;
// log driver: 'syslog' or 'file'.
// log driver: 'syslog', 'stdout' or 'file'.
$config['log_driver'] = 'file';
// date format for log entries

@ -216,11 +216,11 @@ echo '<label for="cfgdebug4">Print errors (to the browser)</label><br />';
<?php
$select_log_driver = new html_select(array('name' => '_log_driver', 'id' => "cfglogdriver"));
$select_log_driver->add(array('file', 'syslog'), array('file', 'syslog'));
$select_log_driver->add(array('file', 'syslog', 'stdout'), array('file', 'syslog', 'stdout'));
echo $select_log_driver->show($RCI->getprop('log_driver', 'file'));
?>
<div>How to do logging? 'file' - write to files in the log directory, 'syslog' - use the syslog facility.</div>
<div>How to do logging? 'file' - write to files in the log directory, 'syslog' - use the syslog facility, 'stdout' writes to the process' STDOUT file descriptor.</div>
</dd>
<dt class="propname">log_dir</dt>

@ -1221,6 +1221,13 @@ class rcube
return syslog($prio, $line);
}
// write message with file name when configured to log to STDOUT
if ($log_driver == 'stdout') {
$stdout = "php://stdout";
$line = "$name: $line";
return file_put_contents($stdout, $line, FILE_APPEND) !== false;
}
// log_driver == 'file' is assumed here
$line = sprintf("[%s]: %s\n", $date, $line);

Loading…
Cancel
Save