Commit 8c75565a authored by Nigel McNie's avatar Nigel McNie
Browse files

Add a two character prefix to each log line, that remains the same over the...

Add a two character prefix to each log line, that remains the same over the lifetime of the request. This makes it easy to distinguish lines between requests that happen at the same time.
parent 6d866b44
...@@ -122,6 +122,12 @@ function log_message ($message, $loglevel, $escape, $backtrace, $file=null, $lin ...@@ -122,6 +122,12 @@ function log_message ($message, $loglevel, $escape, $backtrace, $file=null, $lin
require_once(get_config('docroot') . 'auth/lib.php'); require_once(get_config('docroot') . 'auth/lib.php');
$SESSION = Session::singleton(); $SESSION = Session::singleton();
} }
static $requestprefix = '';
if (!$requestprefix) {
$requestprefix = substr(md5(microtime()), 0, 2) . ' ';
}
static $loglevelnames = array( static $loglevelnames = array(
LOG_LEVEL_ENVIRON => 'environ', LOG_LEVEL_ENVIRON => 'environ',
LOG_LEVEL_DBG => 'dbg', LOG_LEVEL_DBG => 'dbg',
...@@ -163,15 +169,13 @@ function log_message ($message, $loglevel, $escape, $backtrace, $file=null, $lin ...@@ -163,15 +169,13 @@ function log_message ($message, $loglevel, $escape, $backtrace, $file=null, $lin
} }
// Make a prefix for each line, if we are logging a normal debug/info/warn message // Make a prefix for each line, if we are logging a normal debug/info/warn message
$prefix = $requestprefix;
if ($loglevel != LOG_LEVEL_ENVIRON && function_exists('get_config')) { if ($loglevel != LOG_LEVEL_ENVIRON && function_exists('get_config')) {
$docroot = get_config('docroot'); $docroot = get_config('docroot');
$prefixfilename = (substr($filename, 0, strlen($docroot)) == $docroot) $prefixfilename = (substr($filename, 0, strlen($docroot)) == $docroot)
? substr($filename, strlen($docroot)) ? substr($filename, strlen($docroot))
: $filename; : $filename;
$prefix = '(' . $prefixfilename . ':' . $linenum . ') '; $prefix .= '(' . $prefixfilename . ':' . $linenum . ') ';
}
else {
$prefix = '';
} }
$prefix = '[' . str_pad(substr(strtoupper($loglevelnames[$loglevel]), 0, 3), 3) . '] ' . $prefix; $prefix = '[' . str_pad(substr(strtoupper($loglevelnames[$loglevel]), 0, 3), 3) . '] ' . $prefix;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment