3 * log4php is a PHP port of the log4j java logging package.
5 * <p>This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).</p>
6 * <p>Design, strategies and part of the methods documentation are developed by log4j team
7 * (Ceki Gülcü as log4j project founder and
8 * {@link http://jakarta.apache.org/log4j/docs/contributors.html contributors}).</p>
10 * <p>PHP port, extensions and modifications by VxR. All rights reserved.<br>
11 * For more information, please see {@link http://www.vxr.it/log4php/}.</p>
13 * <p>This software is published under the terms of the LGPL License
14 * a copy of which has been included with this distribution in the LICENSE file.</p>
22 if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__));
26 require_once(LOG4PHP_DIR . '/LoggerLog.php');
29 define('LOGGER_MDC_HT_SIZE', 7);
32 * This is the global repository of user mappings
34 $GLOBALS['log4php.LoggerMDC.ht'] = array();
37 * The LoggerMDC class is similar to the {@link LoggerNDC} class except that it is
38 * based on a map instead of a stack. It provides <i>mapped diagnostic contexts</i>.
40 * A <i>Mapped Diagnostic Context</i>, or
41 * MDC in short, is an instrument for distinguishing interleaved log
42 * output from different sources. Log output is typically interleaved
43 * when a server handles multiple clients near-simultaneously.
45 * <p><b><i>The MDC is managed on a per thread basis</i></b>.
47 * @author VxR <vxr@vxr.it>
48 * @version $Revision: 2 $
55 * Put a context value as identified with the key parameter into the current thread's
58 * <p>If the current thread does not have a context map it is
59 * created as a side effect.</p>
61 * <p>Note that you cannot put more than {@link LOGGER_MDC_HT_SIZE} keys.</p>
63 * @param string $key the key
64 * @param string $value the value
67 function put($key, $value)
69 if ( sizeof($GLOBALS['log4php.LoggerMDC.ht']) < LOGGER_MDC_HT_SIZE )
70 $GLOBALS['log4php.LoggerMDC.ht'][$key] = $value;
74 * Get the context identified by the key parameter.
76 * <p>You can use special key identifiers to map values in
77 * PHP $_SERVER and $_ENV vars. Just put a 'server.' or 'env.'
78 * followed by the var name you want to refer.</p>
80 * <p>This method has no side effects.</p>
88 LoggerLog::debug("LoggerMDC::get() key='$key'");
91 if (strpos($key, 'server.') === 0) {
92 $varName = substr($key, 7);
94 LoggerLog::debug("LoggerMDC::get() a _SERVER[$varName] is requested.");
96 return $_SERVER[$varName];
97 } elseif (strpos($key, 'env.') === 0) {
99 $varName = substr($key, 4);
101 LoggerLog::debug("LoggerMDC::get() a _ENV[$varName] is requested.");
103 return $_ENV[$varName];
104 } elseif (isset($GLOBALS['log4php.LoggerMDC.ht'][$key])) {
106 LoggerLog::debug("LoggerMDC::get() a user key is requested.");
108 return $GLOBALS['log4php.LoggerMDC.ht'][$key];
115 * Remove the the context identified by the key parameter.
117 * It only affects user mappings.
123 function remove($key)
125 unset($GLOBALS['log4php.LoggerMDC.ht'][$key]);