From 3c6f74ba235c0c00b8406e0150e827af6a207538 Mon Sep 17 00:00:00 2001 From: Olav Morken <olav.morken@uninett.no> Date: Fri, 7 Aug 2009 14:02:13 +0000 Subject: [PATCH] Logger: Allow the logging handler to be called while initializing logging. git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1642 44740490-163a-0410-bde0-09ae8108e29a --- lib/SimpleSAML/Logger.php | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/SimpleSAML/Logger.php b/lib/SimpleSAML/Logger.php index bb6576687..6b1ff431c 100644 --- a/lib/SimpleSAML/Logger.php +++ b/lib/SimpleSAML/Logger.php @@ -20,6 +20,15 @@ class SimpleSAML_Logger { private static $captureLog = FALSE; private static $capturedLog = array(); + /** + * Array with log messages from before we + * initialized the logging handler. + * + * @var array + */ + private static $earlyLog = array(); + + /** * This constant defines the string we set the trackid to while we are fetching the * trackid from the session class. This is used to prevent infinite recursion. @@ -96,7 +105,10 @@ class SimpleSAML_Logger { public static function createLoggingHandler() { - + + /* Set to FALSE to indicate that it is being initialized. */ + self::$loggingHandler = FALSE; + /* Get the configuration. */ $config = SimpleSAML_Configuration::getInstance(); assert($config instanceof SimpleSAML_Configuration); @@ -134,8 +146,30 @@ class SimpleSAML_Logger { } static function log_internal($level,$string,$statsLog = false) { - if (self::$loggingHandler == null) + if (self::$loggingHandler === NULL) { + /* Initialize logging. */ self::createLoggingHandler(); + + if (!empty(self::$earlyLog)) { + error_log('----------------------------------------------------------------------'); + /* Output messages which were logged before we initialized to the proper log. */ + foreach (self::$earlyLog as $msg) { + self::log_internal($msg['level'], $msg['string'], $msg['statsLog']); + } + } + + } elseif (self::$loggingHandler === FALSE) { + /* Some error occured while initializing logging. */ + if (empty(self::$earlyLog)) { + /* This is the first message. */ + error_log('--- Log message(s) while initializing logging ------------------------'); + } + error_log($string); + + self::$earlyLog[] = array('level' => $level, 'string' => $string, 'statsLog' => $statsLog); + return; + } + if (self::$captureLog) self::$capturedLog[] = $string; -- GitLab