Skip to content

Commit

Permalink
Add Log to STDOUT Feature (#5721)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Jitsusama authored and alecpl committed Apr 10, 2017
1 parent 938dd46 commit 40b51b9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config/defaults.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
// 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
Expand Down
4 changes: 2 additions & 2 deletions installer/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,11 @@
<?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>
Expand Down
7 changes: 7 additions & 0 deletions program/lib/Roundcube/rcube.php
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,13 @@ public static function write_log($name, $line)
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);
Expand Down

0 comments on commit 40b51b9

Please sign in to comment.