| | |
| | | |
| | | // trigger logging hook |
| | | if (is_object(self::$instance) && is_object(self::$instance->plugins)) { |
| | | $log = self::$instance->plugins->exec_hook('write_log', array('name' => $name, 'date' => $date, 'line' => $line)); |
| | | $log = self::$instance->plugins->exec_hook('write_log', |
| | | array('name' => $name, 'date' => $date, 'line' => $line)); |
| | | |
| | | $name = $log['name']; |
| | | $line = $log['line']; |
| | | $date = $log['date']; |
| | | if ($log['abort']) |
| | | |
| | | if ($log['abort']) { |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | // add session ID to the log |
| | |
| | | // 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)) |
| | | if (empty($log_dir) && $name != 'errors') { |
| | | 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)) { |
| | | 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'; |
| | | } |
| | | |
| | | // try to open specific log file for writing |
| | | $logfile = $log_dir.'/'.$name; |
| | | |
| | | if ($fp = @fopen($logfile, 'a')) { |
| | | fwrite($fp, $line); |
| | | fflush($fp); |
| | | fclose($fp); |
| | | return true; |
| | | } |
| | | |
| | | trigger_error("Error writing to log file $logfile; Please check permissions", E_USER_WARNING); |
| | | return false; |
| | | return file_put_contents("$log_dir/$name", $line, FILE_APPEND) !== false; |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | // write error to local log file |
| | | if (($level & 1) || !empty($arg_arr['fatal'])) { |
| | | $post_query = ''; |
| | | if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
| | | $post_query = '?_task='.urlencode($_POST['_task']).'&_action='.urlencode($_POST['_action']); |
| | | } |
| | | else { |
| | | $post_query = ''; |
| | | foreach (array('_task', '_action') as $arg) { |
| | | if ($_POST[$arg] && !$_GET[$arg]) { |
| | | $post_query[$arg] = $_POST[$arg]; |
| | | } |
| | | } |
| | | |
| | | if (!empty($post_query)) { |
| | | $post_query = (strpos($_SERVER['REQUEST_URI'], '?') != false ? '&' : '?') |
| | | . http_build_query($post_query, '', '&'); |
| | | } |
| | | } |
| | | |
| | | $log_entry = sprintf("%s Error: %s%s (%s %s)", |
| | |
| | | $host = preg_replace('/:[0-9]+$/', '', $host); |
| | | if ($host && preg_match('/\.[a-z]+$/i', $host)) { |
| | | $domain_part = $host; |
| | | break; |
| | | } |
| | | } |
| | | } |