diff options
author | Thomas Bruederli <thomas@roundcube.net> | 2014-01-16 12:02:02 +0400 |
---|---|---|
committer | Thomas Bruederli <thomas@roundcube.net> | 2014-01-16 12:02:02 +0400 |
commit | 3786a48aeb27b0ee54694103e0c19808a62ff5e0 (patch) | |
tree | 834603a139096741e34ba0aa4d43a3d7fbd70288 | |
parent | c5f63527101bb20f4c11377f09b53bd406a72714 (diff) |
* New option that write logs to per-user directories. (Debug) logs will only be written if a directory for the current user exists.
* The 'write_log' plugin hook now also supports the return property 'dir' to let plugins specify the log directory.
-rw-r--r-- | config/defaults.inc.php | 4 | ||||
-rw-r--r-- | program/lib/Roundcube/rcube.php | 26 |
2 files changed, 29 insertions, 1 deletions
diff --git a/config/defaults.inc.php b/config/defaults.inc.php index b4c0206ca..b1e3bc85e 100644 --- a/config/defaults.inc.php +++ b/config/defaults.inc.php @@ -73,6 +73,10 @@ $config['syslog_id'] = 'roundcube'; // For possible values see installer or http://php.net/manual/en/function.openlog.php $config['syslog_facility'] = LOG_USER; +// Activate this option if logs should be written to per-user directories. +// Data will only be logged if a directry <log_dir>/<username>/ exists and is writable. +$config['per_user_logging'] = false; + // Log sent messages to <log_dir>/sendmail or to syslog $config['smtp_log'] = true; diff --git a/program/lib/Roundcube/rcube.php b/program/lib/Roundcube/rcube.php index 503e29d6f..d58eb087b 100644 --- a/program/lib/Roundcube/rcube.php +++ b/program/lib/Roundcube/rcube.php @@ -1114,7 +1114,20 @@ class rcube // log_driver == 'file' is assumed here $line = sprintf("[%s]: %s\n", $date, $line); - $log_dir = self::$instance ? self::$instance->config->get('log_dir') : null; + $log_dir = null; + + // per-user logging is activated + if (self::$instance && self::$instance->config->get('per_user_logging', false) && self::$instance->get_user_id()) { + $log_dir = self::$instance->get_user_log_dir(); + if (empty($log_dir)) + return false; + } + else if (!empty($log['dir'])) { + $log_dir = $log['dir']; + } + else if (self::$instance) { + $log_dir = self::$instance->config->get('log_dir'); + } if (empty($log_dir)) { $log_dir = RCUBE_INSTALL_PATH . 'logs'; @@ -1352,6 +1365,17 @@ class rcube } } + /** + * Get the per-user log directory + */ + protected function get_user_log_dir() + { + $log_dir = $this->config->get('log_dir', RCUBE_INSTALL_PATH . 'logs'); + $user_name = $this->get_user_name(); + $user_log_dir = $log_dir . '/' . $user_name; + + return !empty($user_name) && is_writable($user_log_dir) ? $user_log_dir : false; + } /** * Getter for logged user language code. |