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.

The MDC is managed on a per thread basis.

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: 883114 $
  • since: 0.3

Located in /LoggerMDC.php (line 57)


	
			
Method Summary
static string get (string $key)
static void put (string $key, string $value)
static string remove (string $key)
Methods
static get (line 88)

Get the context identified by the key parameter.

You can use special key identifiers to map values in PHP $_SERVER and $_ENV vars. Just put a 'server.' or 'env.' followed by the var name you want to refer.

This method has no side effects.

  • access: public
static string get (string $key)
  • string $key
static put (line 71)

Put a context value as identified with the key parameter into the current thread's context map.

If the current thread does not have a context map it is created as a side effect.

Note that you cannot put more than self::HT_SIZE keys.

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

Remove the the context identified by the key parameter.

It only affects user mappings.

  • access: public
static string remove (string $key)
  • string $key

Documentation generated on Fri, 27 Nov 2009 07:44:51 +0100 by phpDocumentor 1.4.3