From 40b51b9dc96fadeafd944c4039107a01aa106f40 Mon Sep 17 00:00:00 2001 From: Joel Gerber Date: Mon, 10 Apr 2017 07:38:40 -0400 Subject: [PATCH] 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. --- config/defaults.inc.php | 2 +- installer/config.php | 4 ++-- program/lib/Roundcube/rcube.php | 7 +++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/config/defaults.inc.php b/config/defaults.inc.php index 767ee0b83..bd6937c15 100644 --- a/config/defaults.inc.php +++ b/config/defaults.inc.php @@ -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 diff --git a/installer/config.php b/installer/config.php index 19a65bbca..75607187d 100644 --- a/installer/config.php +++ b/installer/config.php @@ -216,11 +216,11 @@ echo '
'; '_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')); ?> -
How to do logging? 'file' - write to files in the log directory, 'syslog' - use the syslog facility.
+
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.
log_dir
diff --git a/program/lib/Roundcube/rcube.php b/program/lib/Roundcube/rcube.php index 173d2878b..7c9d5ccd7 100644 --- a/program/lib/Roundcube/rcube.php +++ b/program/lib/Roundcube/rcube.php @@ -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);