diff --git a/lib/kolab_sync_logger.php b/lib/kolab_sync_logger.php index 2b592d3..4e89757 100644 --- a/lib/kolab_sync_logger.php +++ b/lib/kolab_sync_logger.php @@ -1,143 +1,143 @@ | +--------------------------------------------------------------------------+ | Author: Aleksander Machniak | +--------------------------------------------------------------------------+ */ /** * Class for logging messages into log file(s) */ class kolab_sync_logger extends Zend_Log { public $mode; /** * Constructor */ function __construct($mode = null) { $this->mode = intval($mode); $r = new ReflectionClass($this); $this->_priorities = $r->getConstants(); } public function __call($method, $params) { $method = strtoupper($method); if ($this->_priorities[$method] <= $this->mode) { $this->log(array_shift($params), $method); } } /** * Message logger * * @param string $message Log message * @param int|string $method Message severity */ public function log($message, $method, $extras = null) { $rcube = rcube::get_instance(); $logfile = $rcube->config->get('activesync_log_file'); $format = $rcube->config->get('log_date_format', 'd-M-Y H:i:s O'); $log_dir = $rcube->config->get('log_dir'); if (is_numeric($method)) { $mode = $method; $method = array_search($method, $this->_priorities); } else { $mode = $this->_priorities[$method]; } if ($mode > $this->mode) { return; } // if log_file is configured all logs will go to it // otherwise use separate file for info/debug and warning/error if (!$logfile) { switch ($mode) { case self::DEBUG: case self::INFO: case self::NOTICE: $file = 'console'; break; default: $file = 'errors'; break; } $logfile = $log_dir . DIRECTORY_SEPARATOR . $file; } else if ($logfile[0] != '/') { $logfile = $log_dir . DIRECTORY_SEPARATOR . $logfile; } if (!is_string($message)) { $message = var_export($message, true); } // add user/request information to the log if ($mode <= self::WARN) { $device = array(); $params = array('cmd' => 'Cmd', 'device' => 'DeviceId', 'type' => 'DeviceType'); if (!empty($this->username)) { $device['user'] = $this->username; } foreach ($params as $key => $val) { if ($val = $_GET[$val]) { $device[$key] = $val; } } if (!empty($device)) { $message = @json_encode($device) . ' ' . $message; } } $date = rcube_utils::date_format($format); $logline = sprintf("[%s]: [%s] %s\n", $date, $method, $message); if ($fp = @fopen($logfile, 'a')) { fwrite($fp, $logline); fflush($fp); fclose($fp); return; } if ($mode <= self::WARN) { // send error to PHPs error handler if write to file didn't succeed - trigger_error($message, E_USER_ERROR); + trigger_error($message, E_USER_WARNING); } } /** * Set current user name to add into error log */ public function set_username($username) { $this->username = $username; } }