Index: src/main/php/LoggerMDC.php =================================================================== --- src/main/php/LoggerMDC.php (revision 926129) +++ src/main/php/LoggerMDC.php (working copy) @@ -19,11 +19,6 @@ */ /** - * This is the global repository of user mappings - */ -$GLOBALS['log4php.LoggerMDC.ht'] = array(); - -/** * The LoggerMDC class provides mapped diagnostic contexts. * *

A Mapped Diagnostic Context, or @@ -55,7 +50,13 @@ * @package log4php */ class LoggerMDC { + /** + * This is the repository of user mappings + */ + private static $map = array(); + + /** * Put a context value as identified with the key parameter into the current thread's * context map. * @@ -69,7 +70,7 @@ * @static */ public static function put($key, $value) { - $GLOBALS['log4php.LoggerMDC.ht'][$key] = $value; + self::$map[$key] = $value; } /** @@ -81,20 +82,28 @@ * *

This method has no side effects.

* - * @param string $key - * @return string + * @param string $key the key + * @return string the context or an empty string if no context found + * for given key * @static */ public static function get($key) { if(!empty($key)) { if(strpos($key, 'server.') === 0) { $varName = substr($key, 7); - return @$_SERVER[$varName]; + return isset($_SERVER[$varName]) ? $_SERVER[$varName] : ''; } else if(strpos($key, 'env.') === 0) { $varName = substr($key, 4); - return @$_ENV[$varName]; - } else if (isset($GLOBALS['log4php.LoggerMDC.ht'][$key])) { - return $GLOBALS['log4php.LoggerMDC.ht'][$key]; + /* + * getevn() is used here instead of $_ENV[$varName] because + * $_ENV is not populated on systems where environment + * variable hashing is disabled in php.ini (by ommiting "E" + * from the variables_order directive). + */ + $value = getenv($varName); + return ($value !== false) ? $value : ''; + } else { + return isset(self::$map[$key]) ? self::$map[$key] : ''; } } return ''; @@ -110,7 +119,6 @@ * @static */ public static function remove($key) { - unset($GLOBALS['log4php.LoggerMDC.ht'][$key]); + unset(self::$map[$key]); } - }