Class LoggerMDC

Description

The LoggerMDC class provides mapped diagnostic contexts.

A Mapped Diagnostic Context, or MDC in short, is an instrument for distinguishing interleaved log output from different sources. Log output is typically interleaved when a server handles multiple clients near-simultaneously.

This class is similar to the LoggerNDC class except that it is based on a map instead of a stack.

Example:

  1. require_once dirname(__FILE__).'/../../main/php/Logger.php';
  2.  
  3. Logger::configure(dirname(__FILE__).'/../resources/mdc.properties');
  4. LoggerMDC::put('username''knut');
  5. $logger Logger::getRootLogger();
  6. $logger->debug("Testing MDC");

With the properties file:

  1. log4php.appender.default = LoggerAppenderEcho
  2. log4php.appender.default.layout = LoggerLayoutPattern
  3. log4php.appender.default.layout.conversionPattern="%d{Y-m-d H:i:s} %-5p %c %X{username}: %m in %F at %L%n"
  4. log4php.rootLogger = DEBUG, default

Will result in the following (notice the username "knut" in the output):

 2009-09-13 18:48:28 DEBUG root knut: Testing MDC in src/examples/php/mdc.php at 23

  • version: $Revision: 1212773 $
  • since: 0.3

Located in /LoggerMDC.php (line 50)


	
			
Variable Summary
static mixed $map
Method Summary
static void clear ()
static string get (string $key)
static array getMap ()
static void put (string $key, string $value)
static void remove (string $key)
Variables
static mixed $map = array() (line 53)

Holds the context map.

  • access: private
Methods
static clear (line 115)

Clears the mapped diagnostic context.

  • access: public
static void clear ()
static get (line 77)

Returns the context value identified by the key parameter.

Special key identifiers can be used to map values in the global $_SERVER and $_ENV vars. To access them, use 'server.' or 'env.' followed by the desired var name as the key.

  • return: The context or an empty string if no context found for given key.
  • access: public
static string get (string $key)
  • string $key: The key.
static getMap (line 97)

Returns the contex map as an array.

  • return: The MDC context map.
  • access: public
static array getMap ()
static put (line 62)

Stores a context value as identified with the key parameter into the context map.

  • access: public
static void put (string $key, string $value)
  • string $key: the key
  • string $value: the value
static remove (line 108)

Removes the the context identified by the key parameter.

Only affects user mappings, not $_ENV or $_SERVER.

  • access: public
static void remove (string $key)
  • string $key: The key to be removed.

Documentation generated on Sat, 18 Feb 2012 22:32:25 +0000 by phpDocumentor 1.4.3