Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

php log_driver: Pass all logs to php's configured error_log #6138

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions INSTALL
Expand Up @@ -69,10 +69,11 @@ CONFIGURATION HINTS
IMPORTANT! Read all comments in defaults.inc.php, understand them
and configure your installation to be not surprised by default behaviour.

Roundcube writes internal errors to the 'errors' log file located in the logs
directory which can be configured in config/config.inc.php. If you want ordinary
PHP errors to be logged there as well, enable the 'php_value error_log' line
in the .htaccess file and set the path to the log file accordingly.
By default, Roundcube writes internal errors to the 'errors' log file located
in the logs directory which can be configured in config/config.inc.php. If you
want ordinary PHP errors to be logged there as well, enable the
'php_value error_log' line in the .htaccess file and set the path to the log
file accordingly. Examine the log_driver config value for other options.

By default the session_path settings of PHP are not modified by Roundcube.
However if you want to limit the session cookies to the directory where
Expand Down
2 changes: 1 addition & 1 deletion config/defaults.inc.php
Expand Up @@ -66,7 +66,7 @@
// system error reporting, sum of: 1 = log; 4 = show
$config['debug_level'] = 1;

// log driver: 'syslog', 'stdout' or 'file'.
// log driver: 'syslog', 'stdout', 'file', or 'php'.
$config['log_driver'] = 'file';

// date format for log entries
Expand Down
4 changes: 2 additions & 2 deletions installer/config.php
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', 'stdout'), array('file', 'syslog', 'stdout'));
$select_log_driver->add(array('file', 'syslog', 'stdout', 'php'), array('file', 'syslog', 'stdout', 'php'));
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, 'stdout' writes to the process' STDOUT file descriptor.</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, 'php' writes to php's configured error_log facility.</div>
</dd>

<dt class="propname">log_dir</dt>
Expand Down
2 changes: 1 addition & 1 deletion installer/test.php
Expand Up @@ -87,7 +87,7 @@
<?php

$dirs[] = $RCI->config['temp_dir'] ? $RCI->config['temp_dir'] : 'temp';
if ($RCI->config['log_driver'] != 'syslog')
if ($RCI->config['log_driver'] != 'syslog' && $RCI->config['log_driver'] != 'php')
$dirs[] = $RCI->config['log_dir'] ? $RCI->config['log_dir'] : 'logs';

foreach ($dirs as $dir) {
Expand Down
6 changes: 6 additions & 0 deletions program/lib/Roundcube/rcube.php
Expand Up @@ -1232,6 +1232,12 @@ public static function write_log($name, $line)
return file_put_contents($stdout, $line, FILE_APPEND) !== false;
}

// write to php's configured error_log (or that which is configured in .htaccess)
if ($log_driver == 'php') {
$line = "$name: $line";
return error_log($line);
}

// log_driver == 'file' is assumed here

$line = sprintf("[%s]: %s\n", $date, $line);
Expand Down
6 changes: 4 additions & 2 deletions program/lib/Roundcube/rcube_config.php
Expand Up @@ -247,12 +247,14 @@ private function load()
// set PHP error logging according to config
if ($this->prop['debug_level'] & 1) {
$error_log = $this->prop['log_driver'];
if ($error_log != 'syslog') {
if ($error_log == 'file') {
$error_log = $this->prop['log_dir'] . '/errors';
$error_log .= isset($this->prop['log_file_ext']) ? $this->prop['log_file_ext'] : '.log';
}

ini_set('error_log', $error_log);
if ($error_log != 'php') {
ini_set('error_log', $error_log);
}
ini_set('log_errors', 1);
}

Expand Down