log API improvements and queue optimisation for singleton networks

This commit is contained in:
redmatrix
2015-12-31 12:26:41 -08:00
parent 5f61f57b2c
commit 2cf4ac26fd
7 changed files with 87 additions and 49 deletions

View File

@@ -538,7 +538,7 @@ function attribute_contains($attr, $s) {
* @param int $level A log level.
*/
function logger($msg, $level = 0) {
function logger($msg, $level = LOGGER_NORMAL, $priority = LOG_INFO) {
// turn off logger in install mode
global $a;
global $db;
@@ -559,8 +559,8 @@ function logger($msg, $level = 0) {
$where = basename($stack[0]['file']) . ':' . $stack[0]['line'] . ':' . $stack[1]['function'] . ': ';
}
$s = datetime_convert() . ':' . session_id() . ' ' . $where . $msg . PHP_EOL;
$pluginfo = array('filename' => $logfile, 'loglevel' => $level, 'message' => $s,'logged' => false);
$s = datetime_convert() . ':' . log_priority_str($priority) . ':' . session_id() . ':' . $where . $msg . PHP_EOL;
$pluginfo = array('filename' => $logfile, 'loglevel' => $level, 'message' => $s,'priority' => $priority, 'logged' => false);
call_hooks('logger',$pluginfo);
@@ -568,6 +568,23 @@ function logger($msg, $level = 0) {
@file_put_contents($pluginfo['filename'], $pluginfo['message'], FILE_APPEND);
}
function log_priority_str($priority) {
$parr = array(
LOG_EMERG => 'LOG_EMERG',
LOG_ALERT => 'LOG_ALERT',
LOG_CRIT => 'LOG_CRIT',
LOG_ERR => 'LOG_ERR',
LOG_WARNING => 'LOG_WARNING',
LOG_NOTICE => 'LOG_NOTICE',
LOG_INFO => 'LOG_INFO',
LOG_DEBUG => 'LOG_DEBUG'
);
if($parr[$priority])
return $parr[$priority];
return 'LOG_UNDEFINED';
}
/**
* @brief This is a special logging facility for developers.
*