From 67c026e8d895e2b49db9908c2197a56ce75a98cd Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 12 Sep 2013 16:29:38 +0100 Subject: [PATCH] unique request ID, for associating several log entries with one request --- core/util.inc.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/core/util.inc.php b/core/util.inc.php index 73138cf9..b225dfff 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -923,6 +923,24 @@ function log_warning( /*string*/ $section, /*string*/ $message, $flash=null, $ar function log_error( /*string*/ $section, /*string*/ $message, $flash=null, $args=array()) {log_msg($section, SCORE_LOG_ERROR, $message, $flash, $args);} function log_critical(/*string*/ $section, /*string*/ $message, $flash=null, $args=array()) {log_msg($section, SCORE_LOG_CRITICAL, $message, $flash, $args);} +/** + * Get a unique ID for this request, useful for grouping log messages + */ +$_request_id = null; +function get_request_id() { + global $_request_id; + if(!$_request_id) { + // not completely trustworthy, as a user can spoof this + if(@$_SERVER['HTTP_X_VARNISH']) { + $_request_id = $_SERVER['HTTP_X_VARNISH']; + } + else { + $_request_id = "P" . uniqid(); + } + } + return $_request_id; +} + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ * Things which should be in the core API *