Skip to content

Commit

Permalink
Add 'php' log_driver, passing log entries off to php's configured
Browse files Browse the repository at this point in the history
error_log facility.
  • Loading branch information
noobish committed Nov 10, 2024
1 parent 839694e commit 9183d37
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion config/defaults.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
// LOGGING/DEBUGGING
// ----------------------------------

// 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
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@

<?php
$select_log_driver = new html_select(['name' => '_log_driver', 'id' => 'cfglogdriver']);
$select_log_driver->add(['file', 'syslog', 'stdout'], ['file', 'syslog', 'stdout']);
$select_log_driver->add(['file', 'syslog', 'stdout', 'php'], ['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
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<?php

$dirs = [!empty($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'] ?: 'logs';
}

Expand Down
6 changes: 6 additions & 0 deletions program/lib/Roundcube/rcube.php
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,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
2 changes: 1 addition & 1 deletion program/lib/Roundcube/rcube_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ private function load()
$error_log .= $this->prop['log_file_ext'] ?? '.log';
}

if ($error_log && $error_log != 'stdout') {
if ($error_log && ($error_log != 'stdout' && $error_log != 'php')) {
ini_set('error_log', $error_log);
}

Expand Down

0 comments on commit 9183d37

Please sign in to comment.