summaryrefslogtreecommitdiff
path: root/lib/util.php
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2009-11-27 12:28:15 -0800
committerBrion Vibber <brion@pobox.com>2009-11-27 12:28:15 -0800
commit5bacd98905ed55db6ece546356407f1514fb7fe5 (patch)
tree134831c23a99cddea8213f5ec7a18e9145cbe7b5 /lib/util.php
parent8f7c7b55ba3e0b65d8b7026477fdd849027c9444 (diff)
request id on logs... pid + random id per web request + username + method + url
Diffstat (limited to 'lib/util.php')
-rw-r--r--lib/util.php24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/util.php b/lib/util.php
index 6946f60fe..fa74c2f86 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -1050,8 +1050,32 @@ function common_log_line($priority, $msg)
return date('Y-m-d H:i:s') . ' ' . $syslog_priorities[$priority] . ': ' . $msg . "\n";
}
+function common_request_id()
+{
+ $pid = getmypid();
+ if (php_sapi_name() == 'cli') {
+ return $pid;
+ } else {
+ static $req_id = null;
+ if (!isset($req_id)) {
+ $req_id = substr(md5(mt_rand()), 0, 8);
+ }
+ if (isset($_SERVER['REQUEST_URI'])) {
+ $url = $_SERVER['REQUEST_URI'];
+ }
+ $method = $_SERVER['REQUEST_METHOD'];
+ if (common_logged_in()) {
+ $user = common_current_user()->nickname;
+ } else {
+ $user = 'anon';
+ }
+ return "$pid.$req_id $user $method $url";
+ }
+}
+
function common_log($priority, $msg, $filename=null)
{
+ $msg = '[' . common_request_id() . '] ' . $msg;
$logfile = common_config('site', 'logfile');
if ($logfile) {
$log = fopen($logfile, "a");