extract log-line formatting to its own function

This commit is contained in:
Evan Prodromou 2009-06-28 16:38:27 -04:00
parent cfd2548923
commit 9f079764aa

View File

@ -1104,15 +1104,20 @@ function common_ensure_syslog()
} }
} }
function common_log_line($priority, $msg)
{
static $syslog_priorities = array('LOG_EMERG', 'LOG_ALERT', 'LOG_CRIT', 'LOG_ERR',
'LOG_WARNING', 'LOG_NOTICE', 'LOG_INFO', 'LOG_DEBUG');
return date('Y-m-d H:i:s') . ' ' . $syslog_priorities[$priority] . ': ' . $msg . "\n";
}
function common_log($priority, $msg, $filename=null) function common_log($priority, $msg, $filename=null)
{ {
$logfile = common_config('site', 'logfile'); $logfile = common_config('site', 'logfile');
if ($logfile) { if ($logfile) {
$log = fopen($logfile, "a"); $log = fopen($logfile, "a");
if ($log) { if ($log) {
static $syslog_priorities = array('LOG_EMERG', 'LOG_ALERT', 'LOG_CRIT', 'LOG_ERR', $output = common_log_line($priority, $msg);
'LOG_WARNING', 'LOG_NOTICE', 'LOG_INFO', 'LOG_DEBUG');
$output = date('Y-m-d H:i:s') . ' ' . $syslog_priorities[$priority] . ': ' . $msg . "\n";
fwrite($log, $output); fwrite($log, $output);
fclose($log); fclose($log);
} }