Skip to content
Snippets Groups Projects
Commit 3c6f74ba authored by Olav Morken's avatar Olav Morken
Browse files

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
parent 6463dbed
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,15 @@ class SimpleSAML_Logger { ...@@ -20,6 +20,15 @@ class SimpleSAML_Logger {
private static $captureLog = FALSE; private static $captureLog = FALSE;
private static $capturedLog = array(); 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 * 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. * trackid from the session class. This is used to prevent infinite recursion.
...@@ -96,7 +105,10 @@ class SimpleSAML_Logger { ...@@ -96,7 +105,10 @@ class SimpleSAML_Logger {
public static function createLoggingHandler() { public static function createLoggingHandler() {
/* Set to FALSE to indicate that it is being initialized. */
self::$loggingHandler = FALSE;
/* Get the configuration. */ /* Get the configuration. */
$config = SimpleSAML_Configuration::getInstance(); $config = SimpleSAML_Configuration::getInstance();
assert($config instanceof SimpleSAML_Configuration); assert($config instanceof SimpleSAML_Configuration);
...@@ -134,8 +146,30 @@ class SimpleSAML_Logger { ...@@ -134,8 +146,30 @@ class SimpleSAML_Logger {
} }
static function log_internal($level,$string,$statsLog = false) { static function log_internal($level,$string,$statsLog = false) {
if (self::$loggingHandler == null) if (self::$loggingHandler === NULL) {
/* Initialize logging. */
self::createLoggingHandler(); 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; if (self::$captureLog) self::$capturedLog[] = $string;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment