logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ihabu...@apache.org
Subject [24/43] LOG4PHP-121: Reorganized classes into namespaces
Date Thu, 28 Nov 2013 16:03:54 GMT
http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/LoggingEvent.php
----------------------------------------------------------------------
diff --git a/src/LoggingEvent.php b/src/LoggingEvent.php
new file mode 100644
index 0000000..f0fd7e3
--- /dev/null
+++ b/src/LoggingEvent.php
@@ -0,0 +1,366 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php;
+
+/**
+ * The internal representation of logging event.
+ */
+class LoggingEvent {
+
+	private static $startTime;
+
+	/**
+	* @var string Fully Qualified Class Name of the calling category class.
+	*/
+	private $fqcn;
+
+	/**
+	* @var Logger reference
+	*/
+	private $logger;
+
+	/**
+	 * The category (logger) name.
+	 * This field will be marked as private in future
+	 * releases. Please do not access it directly.
+	 * Use the {@link getLoggerName()} method instead.
+	 * @deprecated
+	 */
+	private $categoryName;
+
+	/**
+	 * Level of the logging event.
+	 * @var Level
+	 */
+	protected $level;
+
+	/**
+	 * The nested diagnostic context (NDC) of logging event.
+	 * @var string
+	 */
+	private $ndc;
+
+	/**
+	 * Have we tried to do an NDC lookup? If we did, there is no need
+	 * to do it again.	Note that its value is always false when
+	 * serialized. Thus, a receiving SocketNode will never use it's own
+	 * (incorrect) NDC. See also writeObject method.
+	 * @var boolean
+	 */
+	private $ndcLookupRequired = true;
+
+	/**
+	 * @var mixed The application supplied message of logging event.
+	 */
+	private $message;
+
+	/**
+	 * The application supplied message rendered through the log4php
+	 * objet rendering mechanism. At present renderedMessage == message.
+	 * @var string
+	 */
+	private $renderedMessage;
+
+	/**
+	 * The name of thread in which this logging event was generated.
+	 * log4php saves here the process id via {@link PHP_MANUAL#getmypid getmypid()}
+	 * @var mixed
+	 */
+	private $threadName;
+
+	/**
+	* The number of seconds elapsed from 1/1/1970 until logging event
+	* was created plus microseconds if available.
+	* @var float
+	*/
+	public $timeStamp;
+
+	/**
+	* @var LocationInfo Location information for the caller.
+	*/
+	private $locationInfo;
+
+	/**
+	 * @var ThrowableInformation log4php internal representation of throwable
+	 */
+	private $throwableInfo;
+
+	/**
+	* Instantiate a LoggingEvent from the supplied parameters.
+	*
+	* Except {@link $timeStamp} all the other fields of
+	* LoggingEvent are filled when actually needed.
+	*
+	* @param string $fqcn name of the caller class.
+	* @param mixed $logger The {@link Logger} category of this event or the logger name.
+	* @param Level $level The level of this event.
+	* @param mixed $message The message of this event.
+	* @param integer $timeStamp the timestamp of this logging event.
+	* @param Exception $throwable The throwable associated with logging event
+	*/
+	public function __construct($fqcn, $logger, Level $level, $message, $timeStamp = null, $throwable = null) {
+		$this->fqcn = $fqcn;
+		if($logger instanceof Logger) {
+			$this->logger = $logger;
+			$this->categoryName = $logger->getName();
+		} else {
+			$this->categoryName = strval($logger);
+		}
+		$this->level = $level;
+		$this->message = $message;
+		if($timeStamp !== null && is_numeric($timeStamp)) {
+			$this->timeStamp = $timeStamp;
+		} else {
+			$this->timeStamp = microtime(true);
+		}
+
+		if (isset($throwable) && $throwable instanceof \Exception) {
+			$this->throwableInfo = new ThrowableInformation($throwable);
+		}
+	}
+
+	/**
+	 * Returns the full qualified classname.
+	 * TODO: PHP does contain namespaces in 5.3. Those should be returned too,
+	 */
+	 public function getFullQualifiedClassname() {
+		 return $this->fqcn;
+	 }
+
+	/**
+	 * Set the location information for this logging event. The collected
+	 * information is cached for future use.
+	 *
+	 * <p>This method uses {@link PHP_MANUAL#debug_backtrace debug_backtrace()} function (if exists)
+	 * to collect informations about caller.</p>
+	 * <p>It only recognize informations generated by {@link Logger} and its subclasses.</p>
+	 * @return LocationInfo
+	 */
+	public function getLocationInformation() {
+		if($this->locationInfo === null) {
+
+			$locationInfo = array();
+			$trace = debug_backtrace();
+			$prevHop = null;
+
+			// make a downsearch to identify the caller
+			$hop = array_pop($trace);
+			while($hop !== null) {
+				if(isset($hop['class'])) {
+					$className = $hop['class'];
+
+					if($className === "Apache\\Log4php\\Logger" ||
+						$className === "Apache\\Log4php\\RootLogger") {
+						$locationInfo['line'] = $hop['line'];
+						$locationInfo['file'] = $hop['file'];
+						break;
+					}
+				}
+				$prevHop = $hop;
+				$hop = array_pop($trace);
+			}
+			$locationInfo['class'] = isset($prevHop['class']) ? $prevHop['class'] : 'main';
+			if(isset($prevHop['function']) and
+				$prevHop['function'] !== 'include' and
+				$prevHop['function'] !== 'include_once' and
+				$prevHop['function'] !== 'require' and
+				$prevHop['function'] !== 'require_once') {
+
+				$locationInfo['function'] = $prevHop['function'];
+			} else {
+				$locationInfo['function'] = 'main';
+			}
+
+			$this->locationInfo = new LocationInfo($locationInfo, $this->fqcn);
+		}
+		return $this->locationInfo;
+	}
+
+	/**
+	 * Return the level of this event. Use this form instead of directly
+	 * accessing the {@link $level} field.
+	 * @return Level
+	 */
+	public function getLevel() {
+		return $this->level;
+	}
+
+	/**
+	 * Returns the logger which created the event.
+	 * @return Logger
+	 */
+	public function getLogger() {
+		return $this->logger;
+	}
+
+	/**
+	 * Return the name of the logger. Use this form instead of directly
+	 * accessing the {@link $categoryName} field.
+	 * @return string
+	 */
+	public function getLoggerName() {
+		return $this->categoryName;
+	}
+
+	/**
+	 * Return the message for this logging event.
+	 * @return mixed
+	 */
+	public function getMessage() {
+		return $this->message;
+	}
+
+	/**
+	 * This method returns the NDC for this event. It will return the
+	 * correct content even if the event was generated in a different
+	 * thread or even on a different machine. The {@link NDC::get()} method
+	 * should <b>never</b> be called directly.
+	 * @return string
+	 */
+	public function getNDC() {
+		if($this->ndcLookupRequired) {
+			$this->ndcLookupRequired = false;
+			$this->ndc = NDC::get();
+		}
+		return $this->ndc;
+	}
+
+	/**
+	 * Returns the the context corresponding to the <code>key</code>
+	 * parameter.
+	 * @return string
+	 */
+	public function getMDC($key) {
+		return MDC::get($key);
+	}
+
+	/**
+	 * Returns the entire MDC context.
+	 * @return array
+	 */
+	public function getMDCMap () {
+		return MDC::getMap();
+	}
+
+	/**
+	 * Render message.
+	 * @return string
+	 */
+	public function getRenderedMessage() {
+		if($this->renderedMessage === null and $this->message !== null) {
+			if(is_string($this->message)) {
+				$this->renderedMessage = $this->message;
+			} else {
+				$rendererMap = Logger::getHierarchy()->getRendererMap();
+				$this->renderedMessage= $rendererMap->findAndRender($this->message);
+			}
+		}
+		return $this->renderedMessage;
+	}
+
+	/**
+	 * Returns the time when the application started, as a UNIX timestamp
+	 * with microseconds.
+	 * @return float
+	 */
+	public static function getStartTime() {
+		if(!isset(self::$startTime)) {
+			self::$startTime = microtime(true);
+		}
+		return self::$startTime;
+	}
+
+	/**
+	 * @return float
+	 */
+	public function getTimeStamp() {
+		return $this->timeStamp;
+	}
+
+	/**
+	 * Returns the time in seconds passed from the beginning of execution to
+	 * the time the event was constructed.
+	 *
+	 * @return float Seconds with microseconds in decimals.
+	 */
+	public function getRelativeTime() {
+		return $this->timeStamp - self::$startTime;
+	}
+
+	/**
+	 * Returns the time in milliseconds passed from the beginning of execution
+	 * to the time the event was constructed.
+	 *
+	 * @deprecated This method has been replaced by getRelativeTime which
+	 * 		does not perform unneccesary multiplication and formatting.
+	 *
+	 * @return integer
+	 */
+	public function getTime() {
+		$eventTime = $this->getTimeStamp();
+		$eventStartTime = LoggingEvent::getStartTime();
+		return number_format(($eventTime - $eventStartTime) * 1000, 0, '', '');
+	}
+
+	/**
+	 * @return mixed
+	 */
+	public function getThreadName() {
+		if ($this->threadName === null) {
+			$this->threadName = (string)getmypid();
+		}
+		return $this->threadName;
+	}
+
+	/**
+	 * @return mixed ThrowableInformation
+	 */
+	public function getThrowableInformation() {
+		return $this->throwableInfo;
+	}
+
+	/**
+	 * Serialize this object
+	 * @return string
+	 */
+	public function toString() {
+		serialize($this);
+	}
+
+	/**
+	 * Avoid serialization of the {@link $logger} object
+	 */
+	public function __sleep() {
+		return array(
+			'fqcn',
+			'categoryName',
+			'level',
+			'ndc',
+			'ndcLookupRequired',
+			'message',
+			'renderedMessage',
+			'threadName',
+			'timeStamp',
+			'locationInfo',
+		);
+	}
+
+}
+
+LoggingEvent::getStartTime();

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/MDC.php
----------------------------------------------------------------------
diff --git a/src/MDC.php b/src/MDC.php
new file mode 100644
index 0000000..9f911c6
--- /dev/null
+++ b/src/MDC.php
@@ -0,0 +1,87 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php;
+
+/**
+ * The MDC 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 {@link NDC} class except that
+ * it is based on a map instead of a stack.
+ *
+ * @since 0.3
+ *
+ */
+class MDC {
+
+	/** Holds the context map. */
+	private static $map = array();
+
+	/**
+	 * Stores a context value as identified with the key parameter into the
+	 * context map.
+	 *
+	 * @param string $key the key
+	 * @param string $value the value
+	 */
+	public static function put($key, $value) {
+		self::$map[$key] = $value;
+	}
+
+	/**
+	 * Returns the context value identified by the key parameter.
+	 *
+	 * @param string $key The key.
+	 * @return string The context or an empty string if no context found
+	 * 	for given key.
+	 */
+	public static function get($key) {
+		return isset(self::$map[$key]) ? self::$map[$key] : '';
+	}
+
+	/**
+	 * Returns the contex map as an array.
+	 * @return array The MDC context map.
+	 */
+	public static function getMap() {
+		return self::$map;
+	}
+
+	/**
+	 * Removes the the context identified by the key parameter.
+	 *
+	 * Only affects user mappings, not $_ENV or $_SERVER.
+	 *
+	 * @param string $key The key to be removed.
+	 */
+	public static function remove($key) {
+		unset(self::$map[$key]);
+	}
+
+	/**
+	 * Clears the mapped diagnostic context.
+	 */
+	public static function clear() {
+		self::$map = array();
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/NDC.php
----------------------------------------------------------------------
diff --git a/src/NDC.php b/src/NDC.php
new file mode 100644
index 0000000..b3de74a
--- /dev/null
+++ b/src/NDC.php
@@ -0,0 +1,184 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php;
+
+/**
+ * The NDC class implements <i>nested diagnostic contexts</i>.
+ *
+ * NDC was defined by Neil Harrison in the article "Patterns for Logging
+ * Diagnostic Messages" part of the book <i>"Pattern Languages of
+ * Program Design 3"</i> edited by Martin et al.
+ *
+ * A Nested Diagnostic Context, or NDC in short, is an instrument
+ * to distinguish 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 {@link MDC} class except that it is
+ * based on a stack instead of a map.
+ *
+ * Interleaved log output can still be meaningful if each log entry
+ * from different contexts had a distinctive stamp. This is where NDCs
+ * come into play.
+ *
+ * <b>Note that NDCs are managed on a per thread basis</b>.
+ *
+ * NDC operations such as {@link push()}, {@link pop()},
+ * {@link clear()}, {@link getDepth()} and {@link setMaxDepth()}
+ * affect the NDC of the <i>current</i> thread only. NDCs of other
+ * threads remain unaffected.
+ *
+ * For example, a servlet can build a per client request NDC
+ * consisting the clients host name and other information contained in
+ * the the request. <i>Cookies</i> are another source of distinctive
+ * information. To build an NDC one uses the {@link push()}
+ * operation.
+ *
+ * Simply put,
+ *
+ * - Contexts can be nested.
+ * - When entering a context, call <kbd>NDC::push()</kbd>
+ *	 As a side effect, if there is no nested diagnostic context for the
+ *	 current thread, this method will create it.
+ * - When leaving a context, call <kbd>NDC::pop()</kbd>
+ * - <b>When exiting a thread make sure to call {@link remove()}</b>
+ *
+ * There is no penalty for forgetting to match each
+ * <kbd>push</kbd> operation with a corresponding <kbd>pop</kbd>,
+ * except the obvious mismatch between the real application context
+ * and the context set in the NDC.
+ *
+ * If configured to do so, {@link LoggerPatternLayout}
+ * instances automatically retrieve the nested diagnostic
+ * context for the current thread without any user intervention.
+ * Hence, even if a servlet is serving multiple clients
+ * simultaneously, the logs emanating from the same code (belonging to
+ * the same category) can still be distinguished because each client
+ * request will have a different NDC tag.
+ *
+ * @since 0.3
+ */
+class NDC {
+
+	/** This is the repository of NDC stack */
+	private static $stack = array();
+
+	/**
+	 * Clear any nested diagnostic information if any. This method is
+	 * useful in cases where the same thread can be potentially used
+	 * over and over in different unrelated contexts.
+	 *
+	 * <p>This method is equivalent to calling the {@link setMaxDepth()}
+	 * method with a zero <var>maxDepth</var> argument.
+	 */
+	public static function clear() {
+		self::$stack = array();
+	}
+
+	/**
+	 * Never use this method directly, use the {@link LoggingEvent::getNDC()} method instead.
+	 * @return array
+	 */
+	public static function get() {
+		return implode(' ', self::$stack);
+	}
+
+	/**
+	 * Get the current nesting depth of this diagnostic context.
+	 *
+	 * @see setMaxDepth()
+	 * @return integer
+	 */
+	public static function getDepth() {
+		return count(self::$stack);
+	}
+
+	/**
+	 * Clients should call this method before leaving a diagnostic
+	 * context.
+	 *
+	 * <p>The returned value is the value that was pushed last. If no
+	 * context is available, then the empty string "" is returned.</p>
+	 *
+	 * @return string The innermost diagnostic context.
+	 */
+	public static function pop() {
+		if(count(self::$stack) > 0) {
+			return array_pop(self::$stack);
+		} else {
+			return '';
+		}
+	}
+
+	/**
+	 * Looks at the last diagnostic context at the top of this NDC
+	 * without removing it.
+	 *
+	 * <p>The returned value is the value that was pushed last. If no
+	 * context is available, then the empty string "" is returned.</p>
+	 * @return string The innermost diagnostic context.
+	 */
+	public static function peek() {
+		if(count(self::$stack) > 0) {
+			return end(self::$stack);
+		} else {
+			return '';
+		}
+	}
+
+	/**
+	 * Push new diagnostic context information for the current thread.
+	 *
+	 * <p>The contents of the <var>message</var> parameter is
+	 * determined solely by the client.
+	 *
+	 * @param string $message The new diagnostic context information.
+	 */
+	public static function push($message) {
+		array_push(self::$stack, (string)$message);
+	}
+
+	/**
+	 * Remove the diagnostic context for this thread.
+	 */
+	public static function remove() {
+		NDC::clear();
+	}
+
+	/**
+	 * Set maximum depth of this diagnostic context. If the current
+	 * depth is smaller or equal to <var>maxDepth</var>, then no
+	 * action is taken.
+	 *
+	 * <p>This method is a convenient alternative to multiple
+	 * {@link pop()} calls. Moreover, it is often the case that at
+	 * the end of complex call sequences, the depth of the NDC is
+	 * unpredictable. The {@link setMaxDepth()} method circumvents
+	 * this problem.
+	 *
+	 * @param integer $maxDepth
+	 * @see getDepth()
+	 */
+	public static function setMaxDepth($maxDepth) {
+		$maxDepth = (int)$maxDepth;
+		if(NDC::getDepth() > $maxDepth) {
+			self::$stack = array_slice(self::$stack, 0, $maxDepth);
+		}
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/Pattern/AbstractConverter.php
----------------------------------------------------------------------
diff --git a/src/Pattern/AbstractConverter.php b/src/Pattern/AbstractConverter.php
new file mode 100644
index 0000000..dc13f4b
--- /dev/null
+++ b/src/Pattern/AbstractConverter.php
@@ -0,0 +1,130 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php\Pattern;
+
+use Apache\Log4php\Helpers\FormattingInfo;
+use Apache\Log4php\LoggingEvent;
+
+/**
+ * AbstractConverter is an abstract class that provides the formatting
+ * functionality that derived classes need.
+ *
+ * <p>Conversion specifiers in a conversion patterns are parsed to
+ * individual PatternConverters. Each of which is responsible for
+ * converting a logging event in a converter specific manner.</p>
+ * @since 0.3
+ */
+abstract class AbstractConverter {
+
+	/**
+	 * Next converter in the converter chain.
+	 * @var AbstractConverter
+	 */
+	public $next = null;
+
+	/**
+	 * Formatting information, parsed from pattern modifiers.
+	 * @var FormattingInfo
+	 */
+	protected $formattingInfo;
+
+	/**
+	 * Converter-specific formatting options.
+	 * @var array
+	 */
+	protected $option;
+
+	/**
+	 * Constructor
+	 * @param FormattingInfo $formattingInfo
+	 * @param array $option
+	 */
+	public function __construct(FormattingInfo $formattingInfo = null, $option = null) {
+		$this->formattingInfo = $formattingInfo;
+		$this->option = $option;
+		$this->activateOptions();
+	}
+
+	/**
+	 * Called in constructor. Converters which need to process the options
+	 * can override this method.
+	 */
+	public function activateOptions() { }
+
+	/**
+	 * Converts the logging event to the desired format. Derived pattern
+	 * converters must implement this method.
+	 *
+	 * @param LoggingEvent $event
+	 */
+	abstract public function convert(LoggingEvent $event);
+
+	/**
+	 * Converts the event and formats it according to setting in the
+	 * Formatting information object.
+	 *
+	 * @param string &$sbuf string buffer to write to
+	 * @param LoggingEvent $event Event to be formatted.
+	 */
+	public function format(&$sbuf, $event) {
+		$string = $this->convert($event);
+
+		if (!isset($this->formattingInfo)) {
+			$sbuf .= $string;
+			return;
+		}
+
+		$fi = $this->formattingInfo;
+
+		// Empty string
+		if($string === '' || is_null($string)) {
+			if($fi->min > 0) {
+				$sbuf .= str_repeat(' ', $fi->min);
+			}
+			return;
+		}
+
+		$len = strlen($string);
+
+		// Trim the string if needed
+		if($len > $fi->max) {
+			if ($fi->trimLeft) {
+				$sbuf .= substr($string, $len - $fi->max, $fi->max);
+			} else {
+				$sbuf .= substr($string , 0, $fi->max);
+			}
+		}
+
+		// Add padding if needed
+		else if($len < $fi->min) {
+			if($fi->padLeft) {
+				$sbuf .= str_repeat(' ', $fi->min - $len);
+				$sbuf .= $string;
+			} else {
+				$sbuf .= $string;
+				$sbuf .= str_repeat(' ', $fi->min - $len);
+			}
+		}
+
+		// No action needed
+		else {
+			$sbuf .= $string;
+		}
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/Pattern/ClassConverter.php
----------------------------------------------------------------------
diff --git a/src/Pattern/ClassConverter.php b/src/Pattern/ClassConverter.php
new file mode 100644
index 0000000..b5e658c
--- /dev/null
+++ b/src/Pattern/ClassConverter.php
@@ -0,0 +1,62 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php\Pattern;
+
+use Apache\Log4php\Helpers\Utils;
+use Apache\Log4php\LoggingEvent;
+
+/**
+ * Returns the fully qualified class name of the class from which the logging
+ * request was issued.
+ * @since 2.3
+ */
+class ClassConverter extends AbstractConverter {
+
+	/** Length to which to shorten the class name. */
+	private $length;
+
+	/** Holds processed class names. */
+	private $cache = array();
+
+	public function activateOptions() {
+		// Parse the option (desired output length)
+		if (isset($this->option) && is_numeric($this->option) && $this->option >= 0) {
+			$this->length = (integer) $this->option;
+		}
+	}
+
+	public function convert(LoggingEvent $event) {
+		$name = $event->getLocationInformation()->getClassName();
+
+		if (!isset($this->cache[$name])) {
+
+			// If length is set return shortened class name
+			if (isset($this->length)) {
+				$this->cache[$name] = Utils::shortenClassName($name, $this->length);
+			}
+
+			// If no length is specified return the full class name
+			else {
+				$this->cache[$name] = $name;
+			}
+		}
+
+		return $this->cache[$name];
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/Pattern/CookieConverter.php
----------------------------------------------------------------------
diff --git a/src/Pattern/CookieConverter.php b/src/Pattern/CookieConverter.php
new file mode 100644
index 0000000..69b5738
--- /dev/null
+++ b/src/Pattern/CookieConverter.php
@@ -0,0 +1,32 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php\Pattern;
+
+/**
+ * Returns a value from the $_COOKIE superglobal array corresponding to the
+ * given key. If no key is given, return all values.
+ *
+ * Options:
+ *  [0] $_COOKIE key value
+ *
+ * @since 2.3
+ */
+class CookieConverter extends SuperglobalConverter {
+	protected $name = '_COOKIE';
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/Pattern/DateConverter.php
----------------------------------------------------------------------
diff --git a/src/Pattern/DateConverter.php b/src/Pattern/DateConverter.php
new file mode 100644
index 0000000..5a1ad4a
--- /dev/null
+++ b/src/Pattern/DateConverter.php
@@ -0,0 +1,89 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php\Pattern;
+
+use Apache\Log4php\LoggingEvent;
+
+/**
+ * Returns the date/time of the logging request.
+ *
+ * Option: the datetime format, as used by the date() function. If
+ * the option is not given, the default format 'c' will be used.
+ *
+ * There are several "special" values which can be given for this option:
+ * 'ISO8601', 'ABSOLUTE' and 'DATE'.
+ * @since 2.3
+ */
+class DateConverter extends AbstractConverter {
+
+	const DATE_FORMAT_ISO8601 = 'c';
+
+	const DATE_FORMAT_ABSOLUTE = 'H:i:s';
+
+	const DATE_FORMAT_DATE = 'd M Y H:i:s.u';
+
+	private $format = self::DATE_FORMAT_ISO8601;
+
+	private $specials = array(
+		'ISO8601' => self::DATE_FORMAT_ISO8601,
+		'ABSOLUTE' => self::DATE_FORMAT_ABSOLUTE,
+		'DATE' => self::DATE_FORMAT_DATE,
+	);
+
+	private $useLocalDate = false;
+
+	public function activateOptions() {
+
+		// Parse the option (date format)
+		if (!empty($this->option)) {
+			if(isset($this->specials[$this->option])) {
+				$this->format = $this->specials[$this->option];
+			} else {
+				$this->format = $this->option;
+			}
+		}
+
+		// Check whether the pattern contains milliseconds (u)
+		if (preg_match('/(?<!\\\\)u/', $this->format)) {
+			$this->useLocalDate = true;
+		}
+	}
+
+	public function convert(LoggingEvent $event) {
+		if ($this->useLocalDate) {
+			return $this->date($this->format, $event->getTimeStamp());
+		}
+		return date($this->format, $event->getTimeStamp());
+	}
+
+	/**
+	 * Currently, PHP date() function always returns zeros for milliseconds (u)
+	 * on Windows. This is a replacement function for date() which correctly
+	 * displays milliseconds on all platforms.
+	 *
+	 * It is slower than PHP date() so it should only be used if necessary.
+	 */
+	private function date($format, $utimestamp) {
+		$timestamp = floor($utimestamp);
+		$ms = floor(($utimestamp - $timestamp) * 1000);
+		$ms = str_pad($ms, 3, '0', STR_PAD_LEFT);
+
+		return date(preg_replace('`(?<!\\\\)u`', $ms, $format), $timestamp);
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/Pattern/EnvironmentConverter.php
----------------------------------------------------------------------
diff --git a/src/Pattern/EnvironmentConverter.php b/src/Pattern/EnvironmentConverter.php
new file mode 100644
index 0000000..7be0272
--- /dev/null
+++ b/src/Pattern/EnvironmentConverter.php
@@ -0,0 +1,33 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php\Pattern;
+
+/**
+ * Returns a value from the $_ENV superglobal array corresponding to the
+ * given key.
+ *
+ * Options:
+ *  [0] $_ENV key value
+ *
+ *
+ * @since 2.3
+ */
+class EnvironmentConverter extends SuperglobalConverter {
+	protected $name = '_ENV';
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/Pattern/FileConverter.php
----------------------------------------------------------------------
diff --git a/src/Pattern/FileConverter.php b/src/Pattern/FileConverter.php
new file mode 100644
index 0000000..809192d
--- /dev/null
+++ b/src/Pattern/FileConverter.php
@@ -0,0 +1,32 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php\Pattern;
+
+use Apache\Log4php\LoggingEvent;
+
+/**
+ * Returns the name of the file from which the logging request was issued.
+ * @since 2.3
+ */
+class FileConverter extends AbstractConverter {
+
+	public function convert(LoggingEvent $event) {
+		return $event->getLocationInformation()->getFileName();
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/Pattern/LevelConverter.php
----------------------------------------------------------------------
diff --git a/src/Pattern/LevelConverter.php b/src/Pattern/LevelConverter.php
new file mode 100644
index 0000000..3b42fe0
--- /dev/null
+++ b/src/Pattern/LevelConverter.php
@@ -0,0 +1,32 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php\Pattern;
+
+use Apache\Log4php\LoggingEvent;
+
+/**
+ * Returns the event's level.
+ * @since 2.3
+ */
+class LevelConverter extends AbstractConverter {
+
+	public function convert(LoggingEvent $event) {
+		return $event->getLevel()->toString();
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/Pattern/LineConverter.php
----------------------------------------------------------------------
diff --git a/src/Pattern/LineConverter.php b/src/Pattern/LineConverter.php
new file mode 100644
index 0000000..659fa11
--- /dev/null
+++ b/src/Pattern/LineConverter.php
@@ -0,0 +1,33 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php\Pattern;
+
+use Apache\Log4php\LoggingEvent;
+
+/**
+ * Returns the line number within the file from which the logging request was
+ * issued.
+ * @since 2.3
+ */
+class LineConverter extends AbstractConverter {
+
+	public function convert(LoggingEvent $event) {
+		return $event->getLocationInformation()->getLineNumber();
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/Pattern/LiteralConverter.php
----------------------------------------------------------------------
diff --git a/src/Pattern/LiteralConverter.php b/src/Pattern/LiteralConverter.php
new file mode 100644
index 0000000..089fa7f
--- /dev/null
+++ b/src/Pattern/LiteralConverter.php
@@ -0,0 +1,38 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php\Pattern;
+
+use Apache\Log4php\LoggingEvent;
+
+/**
+ * Returns the literal value passed in the constructor, without modifications.
+ * @since 2.3
+ */
+class LiteralConverter extends AbstractConverter {
+
+	private $literalValue;
+
+	public function __construct($literalValue) {
+		$this->literalValue = $literalValue;
+	}
+
+	public function convert(LoggingEvent $event) {
+		return $this->literalValue;
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/Pattern/LocationConverter.php
----------------------------------------------------------------------
diff --git a/src/Pattern/LocationConverter.php b/src/Pattern/LocationConverter.php
new file mode 100644
index 0000000..4334ec7
--- /dev/null
+++ b/src/Pattern/LocationConverter.php
@@ -0,0 +1,37 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php\Pattern;
+
+use Apache\Log4php\LoggingEvent;
+
+/**
+ * Returns the line number within the file from which the logging request was
+ * issued.
+ * @since 2.3
+ */
+class LocationConverter extends AbstractConverter {
+
+	public function convert(LoggingEvent $event) {
+		return
+			$event->getLocationInformation()->getClassName() . '.' .
+			$event->getLocationInformation()->getMethodName() . '(' .
+			$event->getLocationInformation()->getFileName() . ':' .
+			$event->getLocationInformation()->getLineNumber() . ')';
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/Pattern/LoggerConverter.php
----------------------------------------------------------------------
diff --git a/src/Pattern/LoggerConverter.php b/src/Pattern/LoggerConverter.php
new file mode 100644
index 0000000..0433659
--- /dev/null
+++ b/src/Pattern/LoggerConverter.php
@@ -0,0 +1,64 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php\Pattern;
+
+use Apache\Log4php\Helpers\Utils;
+use Apache\Log4php\LoggingEvent;
+
+/**
+ * Returns the name of the logger which created the logging request.
+ *
+ * Takes one option, which is an integer. If the option is given, the logger
+ * name will be shortened to the given length, if possible.
+ * @since 2.3
+ */
+class LoggerConverter extends AbstractConverter {
+
+	/** Length to which to shorten the name. */
+	private $length;
+
+	/** Holds processed logger names. */
+	private $cache = array();
+
+	public function activateOptions() {
+		// Parse the option (desired output length)
+		if (isset($this->option) && is_numeric($this->option) && $this->option >= 0) {
+			$this->length = (integer) $this->option;
+		}
+	}
+
+	public function convert(LoggingEvent $event) {
+		$name = $event->getLoggerName();
+
+		if (!isset($this->cache[$name])) {
+
+			// If length is set return shortened logger name
+			if (isset($this->length)) {
+				$this->cache[$name] = Utils::shortenClassName($name, $this->length);
+			}
+
+			// If no length is specified return full logger name
+			else {
+				$this->cache[$name] = $name;
+			}
+		}
+
+		return $this->cache[$name];
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/Pattern/MdcConverter.php
----------------------------------------------------------------------
diff --git a/src/Pattern/MdcConverter.php b/src/Pattern/MdcConverter.php
new file mode 100644
index 0000000..cb50c8e
--- /dev/null
+++ b/src/Pattern/MdcConverter.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php\Pattern;
+
+use Apache\Log4php\LoggingEvent;
+
+/**
+ * Returns the Mapped Diagnostic Context value corresponding to the given key.
+ *
+ * Options:
+ *  [0] the MDC key
+ * @since 2.3
+ */
+class MdcConverter extends AbstractConverter {
+
+	private $key;
+
+	public function activateOptions() {
+		if (isset($this->option) && $this->option !== '') {
+			$this->key = $this->option;
+		}
+	}
+
+	public function convert(LoggingEvent $event) {
+		if (isset($this->key)) {
+			return $event->getMDC($this->key);
+		} else {
+			$buff = array();
+			$map = $event->getMDCMap();
+			foreach($map as $key => $value) {
+				$buff []= "$key=$value";
+			}
+			return implode(', ', $buff);
+		}
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/Pattern/MessageConverter.php
----------------------------------------------------------------------
diff --git a/src/Pattern/MessageConverter.php b/src/Pattern/MessageConverter.php
new file mode 100644
index 0000000..acd53d8
--- /dev/null
+++ b/src/Pattern/MessageConverter.php
@@ -0,0 +1,32 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php\Pattern;
+
+use Apache\Log4php\LoggingEvent;
+
+/**
+ * Returns the logged message.
+ * @since 2.3
+ */
+class MessageConverter extends AbstractConverter {
+
+	public function convert(LoggingEvent $event) {
+		return $event->getRenderedMessage();
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/Pattern/MethodConverter.php
----------------------------------------------------------------------
diff --git a/src/Pattern/MethodConverter.php b/src/Pattern/MethodConverter.php
new file mode 100644
index 0000000..d0c29e8
--- /dev/null
+++ b/src/Pattern/MethodConverter.php
@@ -0,0 +1,33 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php\Pattern;
+
+use Apache\Log4php\LoggingEvent;
+
+/**
+ * Returns the name of the function or method from which the logging request
+ * was issued.
+ * @since 2.3
+ */
+class MethodConverter extends AbstractConverter {
+
+	public function convert(LoggingEvent $event) {
+		return $event->getLocationInformation()->getMethodName();
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/Pattern/NdcConverter.php
----------------------------------------------------------------------
diff --git a/src/Pattern/NdcConverter.php b/src/Pattern/NdcConverter.php
new file mode 100644
index 0000000..fb0027e
--- /dev/null
+++ b/src/Pattern/NdcConverter.php
@@ -0,0 +1,32 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php\Pattern;
+
+use Apache\Log4php\LoggingEvent;
+
+/**
+ * Returns the full Nested Diagnostic Context.
+ * @since 2.3
+ */
+class NdcConverter extends AbstractConverter {
+
+	public function convert(LoggingEvent $event) {
+		return $event->getNDC();
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/Pattern/NewLineConverter.php
----------------------------------------------------------------------
diff --git a/src/Pattern/NewLineConverter.php b/src/Pattern/NewLineConverter.php
new file mode 100644
index 0000000..2e3f7e6
--- /dev/null
+++ b/src/Pattern/NewLineConverter.php
@@ -0,0 +1,32 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php\Pattern;
+
+use Apache\Log4php\LoggingEvent;
+
+/**
+ * Returns platform-specific newline character(s).
+ * @since 2.3
+ */
+class NewLineConverter extends AbstractConverter {
+
+	public function convert(LoggingEvent $event) {
+		return PHP_EOL;
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/Pattern/ProcessConverter.php
----------------------------------------------------------------------
diff --git a/src/Pattern/ProcessConverter.php b/src/Pattern/ProcessConverter.php
new file mode 100644
index 0000000..4ba2151
--- /dev/null
+++ b/src/Pattern/ProcessConverter.php
@@ -0,0 +1,32 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php\Pattern;
+
+use Apache\Log4php\LoggingEvent;
+
+/**
+ * Returns the PID of the current process.
+ * @since 2.3
+ */
+class ProcessConverter extends AbstractConverter {
+
+	public function convert(LoggingEvent $event) {
+		return getmypid();
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/Pattern/RelativeConverter.php
----------------------------------------------------------------------
diff --git a/src/Pattern/RelativeConverter.php b/src/Pattern/RelativeConverter.php
new file mode 100644
index 0000000..d6e3111
--- /dev/null
+++ b/src/Pattern/RelativeConverter.php
@@ -0,0 +1,34 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php\Pattern;
+
+use Apache\Log4php\LoggingEvent;
+
+/**
+ * Returns the number of milliseconds elapsed since the start of the
+ * application until the creation of the logging event.
+ * @since 2.3
+ */
+class RelativeConverter extends AbstractConverter {
+
+	public function convert(LoggingEvent $event) {
+		$ts = $event->getRelativeTime();
+		return number_format($ts, 4);
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/Pattern/RequestConverter.php
----------------------------------------------------------------------
diff --git a/src/Pattern/RequestConverter.php b/src/Pattern/RequestConverter.php
new file mode 100644
index 0000000..5440e75
--- /dev/null
+++ b/src/Pattern/RequestConverter.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php\Pattern;
+
+use Apache\Log4php\LoggingEvent;
+
+/**
+ * Returns a value from the $_REQUEST superglobal array corresponding to the
+ * given key.
+ *
+ * Options:
+ *  [0] $_REQUEST key value
+ *
+ *
+ * @since 2.3
+ */
+class RequestConverter extends SuperglobalConverter {
+	protected $name = '_REQUEST';
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/Pattern/ServerConverter.php
----------------------------------------------------------------------
diff --git a/src/Pattern/ServerConverter.php b/src/Pattern/ServerConverter.php
new file mode 100644
index 0000000..c6085ce
--- /dev/null
+++ b/src/Pattern/ServerConverter.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php\Pattern;
+
+use Apache\Log4php\LoggingEvent;
+
+/**
+ * Returns a value from the $_SERVER superglobal array corresponding to the
+ * given key.
+ *
+ * Options:
+ *  [0] $_SERVER key value
+ *
+ *
+ * @since 2.3
+ */
+class ServerConverter extends SuperglobalConverter {
+	protected $name = '_SERVER';
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/Pattern/SessionConverter.php
----------------------------------------------------------------------
diff --git a/src/Pattern/SessionConverter.php b/src/Pattern/SessionConverter.php
new file mode 100644
index 0000000..c5d812b
--- /dev/null
+++ b/src/Pattern/SessionConverter.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php\Pattern;
+
+use Apache\Log4php\LoggingEvent;
+
+/**
+ * Returns a value from the $_SESSION superglobal array corresponding to the
+ * given key.
+ *
+ * Options:
+ *  [0] $_SESSION key value
+ *
+ *
+ * @since 2.3
+ */
+class SessionConverter extends SuperglobalConverter {
+	protected $name = '_SESSION';
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/Pattern/SessionIdConverter.php
----------------------------------------------------------------------
diff --git a/src/Pattern/SessionIdConverter.php b/src/Pattern/SessionIdConverter.php
new file mode 100644
index 0000000..c5d622c
--- /dev/null
+++ b/src/Pattern/SessionIdConverter.php
@@ -0,0 +1,31 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php\Pattern;
+
+use Apache\Log4php\LoggingEvent;
+
+/**
+ * Returns the active session ID, or an empty string if out of session.
+ * @since 2.3
+ */
+class SessionIdConverter extends AbstractConverter {
+	public function convert(LoggingEvent $event) {
+		return session_id();
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/Pattern/SuperglobalConverter.php
----------------------------------------------------------------------
diff --git a/src/Pattern/SuperglobalConverter.php b/src/Pattern/SuperglobalConverter.php
new file mode 100644
index 0000000..c43d0c0
--- /dev/null
+++ b/src/Pattern/SuperglobalConverter.php
@@ -0,0 +1,100 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php\Pattern;
+
+use Apache\Log4php\LoggingEvent;
+
+/**
+ * Returns a value from a superglobal array corresponding to the
+ * given key.
+ *
+ * Option: the key to look up within the superglobal array
+ *
+ * Also, it is possible that a superglobal variable is not populated by PHP
+ * because of the settings in the variables-order ini directive. In this case
+ * the converter will return an empty value.
+ *
+ * @see http://php.net/manual/en/language.variables.superglobals.php
+ * @see http://www.php.net/manual/en/ini.core.php#ini.variables-order
+ * @since 2.3
+ */
+abstract class SuperglobalConverter extends AbstractConverter {
+
+	/**
+	 * Name of the superglobal variable, to be defined by subclasses.
+	 * For example: "_SERVER" or "_ENV".
+	 */
+	protected $name;
+
+	protected $value = '';
+
+	public function activateOptions() {
+		// Read the key from options array
+		if (isset($this->option) && $this->option !== '') {
+			$key = $this->option;
+		}
+
+		/*
+		 * There is a bug in PHP which doesn't allow superglobals to be
+		 * accessed when their name is stored in a variable, e.g.:
+		 *
+		 * $name = '_SERVER';
+		 * $array = $$name;
+		 *
+		 * This code does not work when run from within a method (only when run
+		 * in global scope). But the following code does work:
+		 *
+		 * $name = '_SERVER';
+		 * global $$name;
+		 * $array = $$name;
+		 *
+		 * That's why global is used here.
+		 */
+		global ${$this->name};
+
+		// Check the given superglobal exists. It is possible that it is not initialized.
+		if (!isset(${$this->name})) {
+			$class = basename(get_class($this));
+			trigger_error("log4php: $class: Cannot find superglobal variable \${$this->name}.", E_USER_WARNING);
+			return;
+		}
+
+		$source = ${$this->name};
+
+		// When the key is set, display the matching value
+		if (isset($key)) {
+			if (isset($source[$key])) {
+				$this->value = $source[$key];
+			}
+		}
+
+		// When the key is not set, display all values
+		else {
+			$values = array();
+			foreach($source as $key => $value) {
+				$values[] = "$key=$value";
+			}
+			$this->value = implode(', ', $values);
+		}
+	}
+
+	public function convert(LoggingEvent $event) {
+		return $this->value;
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/Pattern/ThrowableConverter.php
----------------------------------------------------------------------
diff --git a/src/Pattern/ThrowableConverter.php b/src/Pattern/ThrowableConverter.php
new file mode 100644
index 0000000..f18e322
--- /dev/null
+++ b/src/Pattern/ThrowableConverter.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php\Pattern;
+
+/**
+ * Returns the throwable information linked to the logging event, if any.
+ * @since 2.3
+ */
+class ThrowableConverter extends AbstractConverter {
+
+	public function convert(LoggingEvent $event) {
+		$info = $event->getThrowableInformation();
+		if (isset($info)) {
+			$ex = $info->getThrowable();
+			return (string) $ex . PHP_EOL;
+		}
+		return '';
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/ReflectionUtils.php
----------------------------------------------------------------------
diff --git a/src/ReflectionUtils.php b/src/ReflectionUtils.php
new file mode 100644
index 0000000..cc39ec3
--- /dev/null
+++ b/src/ReflectionUtils.php
@@ -0,0 +1,151 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php;
+
+/**
+ * Provides methods for reflective use on php objects
+ */
+class ReflectionUtils {
+
+	/** the target object */
+	private $obj;
+
+	/**
+	 * Create a new ReflectionUtils for the specified Object.
+	 * This is done in prepartion for invoking {@link setProperty()}
+	 * one or more times.
+	 * @param object &$obj the object for which to set properties
+	 */
+	public function __construct($obj) {
+		$this->obj = $obj;
+	}
+
+	/**
+	 * Set the properties of an object passed as a parameter in one
+	 * go. The <code>properties</code> are parsed relative to a
+	 * <code>prefix</code>.
+	 *
+	 * @param object $obj The object to configure.
+	 * @param array $properties An array containing keys and values.
+	 * @param string $prefix Only keys having the specified prefix will be set.
+	 */
+	 // TODO: check, if this is really useful
+	public static function setPropertiesByObject($obj, $properties, $prefix) {
+		$pSetter = new ReflectionUtils($obj);
+		return $pSetter->setProperties($properties, $prefix);
+	}
+
+	/**
+	 * Set the properites for the object that match the
+	 * <code>prefix</code> passed as parameter.
+	 *
+	 * Example:
+	 *
+	 * $arr['xxxname'] = 'Joe';
+ 	 * $arr['xxxmale'] = true;
+	 * and prefix xxx causes setName and setMale.
+	 *
+	 * @param array $properties An array containing keys and values.
+	 * @param string $prefix Only keys having the specified prefix will be set.
+	 */
+	public function setProperties($properties, $prefix) {
+		$len = strlen($prefix);
+		reset($properties);
+		while(list($key,) = each($properties)) {
+			if(strpos($key, $prefix) === 0) {
+				if(strpos($key, '.', ($len + 1)) > 0) {
+					continue;
+				}
+				$value = $properties[$key];
+				$key = substr($key, $len);
+				if($key == 'layout' and ($this->obj instanceof Appender)) {
+					continue;
+				}
+				$this->setProperty($key, $value);
+			}
+		}
+		$this->activate();
+	}
+
+	/**
+	 * Set a property on this PropertySetter's Object. If successful, this
+	 * method will invoke a setter method on the underlying Object. The
+	 * setter is the one for the specified property name and the value is
+	 * determined partly from the setter argument type and partly from the
+	 * value specified in the call to this method.
+	 *
+	 * <p>If the setter expects a String no conversion is necessary.
+	 * If it expects an int, then an attempt is made to convert 'value'
+	 * to an int using new Integer(value). If the setter expects a boolean,
+	 * the conversion is by new Boolean(value).
+	 *
+	 * @param string $name	name of the property
+	 * @param string $value	String value of the property
+	 */
+	public function setProperty($name, $value) {
+		if($value === null) {
+			return;
+		}
+
+		$method = "set" . ucfirst($name);
+
+		if(!method_exists($this->obj, $method)) {
+			throw new Exception("Error setting log4php property $name to $value: no method $method in class ".get_class($this->obj)."!");
+		} else {
+			return call_user_func(array($this->obj, $method), $value);
+		}
+	}
+
+	public function activate() {
+		if(method_exists($this->obj, 'activateoptions')) {
+			return call_user_func(array($this->obj, 'activateoptions'));
+		}
+	}
+
+	/**
+	 * Creates an instances from the given class name.
+	 *
+	 * @param string $classname
+	 * @return an object from the class with the given classname
+	 */
+	public static function createObject($class) {
+		if(!empty($class)) {
+			return new $class();
+		}
+		return null;
+	}
+
+	/**
+	 * @param object $object
+	 * @param string $name
+	 * @param mixed $value
+	 */
+	public static function setter($object, $name, $value) {
+		if (empty($name)) {
+			return false;
+		}
+		$methodName = 'set'.ucfirst($name);
+		if (method_exists($object, $methodName)) {
+			return call_user_func(array($object, $methodName), $value);
+		} else {
+			return false;
+		}
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/Renderers/DefaultRenderer.php
----------------------------------------------------------------------
diff --git a/src/Renderers/DefaultRenderer.php b/src/Renderers/DefaultRenderer.php
new file mode 100644
index 0000000..78b844c
--- /dev/null
+++ b/src/Renderers/DefaultRenderer.php
@@ -0,0 +1,33 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php\Renderers;
+
+/**
+ * The default renderer, which is used when no other renderer is found.
+ *
+ * Renders the input using <var>print_r</var>.
+ * @since 0.3
+ */
+class DefaultRenderer implements RendererInterface {
+
+	/** @inheritdoc */
+	public function render($input) {
+		return print_r($input, true);
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/Renderers/ExceptionRenderer.php
----------------------------------------------------------------------
diff --git a/src/Renderers/ExceptionRenderer.php b/src/Renderers/ExceptionRenderer.php
new file mode 100644
index 0000000..d625ae8
--- /dev/null
+++ b/src/Renderers/ExceptionRenderer.php
@@ -0,0 +1,33 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php\Renderers;
+
+/**
+ * Renderer used for Exceptions.
+ * @since 2.1
+ */
+class ExceptionRenderer implements RendererInterface {
+
+	public function render($input) {
+
+		// Exception class has a very decent __toString method
+		// so let's just use that instead of writing lots of code.
+		return (string) $input;
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/Renderers/RendererInterface.php
----------------------------------------------------------------------
diff --git a/src/Renderers/RendererInterface.php b/src/Renderers/RendererInterface.php
new file mode 100644
index 0000000..8bfda22
--- /dev/null
+++ b/src/Renderers/RendererInterface.php
@@ -0,0 +1,32 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php\Renderers;
+
+/**
+ * Implement this interface in order to render objects to strings.
+ * @since 0.3
+ */
+interface RendererInterface {
+	/**
+	 * Renders the entity passed as <var>input</var> to a string.
+	 * @param mixed $input The entity to render.
+	 * @return string The rendered string.
+	 */
+	public function render($input);
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/Renderers/RendererMap.php
----------------------------------------------------------------------
diff --git a/src/Renderers/RendererMap.php b/src/Renderers/RendererMap.php
new file mode 100644
index 0000000..1444d25
--- /dev/null
+++ b/src/Renderers/RendererMap.php
@@ -0,0 +1,189 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php\Renderers;
+
+/**
+ * Manages defined renderers and determines which renderer to use for a given
+ * input.
+ * @since 0.3
+ */
+class RendererMap {
+
+	/**
+	 * Maps class names to appropriate renderers.
+	 * @var array
+	 */
+	private $map = array();
+
+	/**
+	 * The default renderer to use if no specific renderer is found.
+	 * @var RendererInterface
+	 */
+	private $defaultRenderer;
+
+	public function __construct() {
+
+		// Set default config
+		$this->reset();
+	}
+
+	/**
+	 * Adds a renderer to the map.
+	 *
+	 * If a renderer already exists for the given <var>$renderedClass</var> it
+	 * will be overwritten without warning.
+	 *
+	 * @param string $renderedClass The name of the class which will be
+	 * 		rendered by the renderer.
+	 * @param string $renderingClass The name of the class which will
+	 * 		perform the rendering.
+	 */
+	public function addRenderer($renderedClass, $renderingClass) {
+
+		if (class_exists($renderingClass)) {
+			$renderer = new $renderingClass();
+		} else {
+			// Try to find renderer in the default namespace
+			$namespaced = "Apache\\Log4php\\Renderers\\$renderingClass";
+			if (class_exists($namespaced)) {
+				$renderer = new $namespaced();
+			}
+		}
+
+		if (!isset($renderer)) {
+			trigger_error("log4php: Failed adding renderer. Rendering class [$renderingClass] not found.");
+			return;
+		}
+
+		// Check the class implements the right interface
+		if (!($renderer instanceof RendererInterface)) {
+			trigger_error("log4php: Failed adding renderer. Rendering class [$renderingClass] does not implement the RendererInterface interface.");
+			return;
+		}
+
+		// Convert to lowercase since class names in PHP are not case sensitive
+		$renderedClass = strtolower($renderedClass);
+
+		$this->map[$renderedClass] = $renderer;
+	}
+
+	/**
+	 * Sets a custom default renderer class.
+	 *
+	 * TODO: there's code duplication here. This method is almost identical to
+	 * addRenderer(). However, it has custom error messages so let it sit for
+	 * now.
+	 *
+	 * @param string $renderingClass The name of the class which will
+	 * 		perform the rendering.
+	 */
+	public function setDefaultRenderer($renderingClass) {
+		// Check the class exists
+		if (!class_exists($renderingClass)) {
+			trigger_error("log4php: Failed setting default renderer. Rendering class [$renderingClass] not found.");
+			return;
+		}
+
+		// Create the instance
+		$renderer = new $renderingClass();
+
+		// Check the class implements the right interface
+		if (!($renderer instanceof RendererInterface)) {
+			trigger_error("log4php: Failed setting default renderer. Rendering class [$renderingClass] does not implement the RendererInterface interface.");
+			return;
+		}
+
+		$this->defaultRenderer = $renderer;
+	}
+
+	/**
+	 * Returns the default renderer.
+	 * @var RendererInterface
+	 */
+	public function getDefaultRenderer() {
+		return $this->defaultRenderer;
+	}
+
+	/**
+	 * Finds the appropriate renderer for the given <var>input</var>, and
+	 * renders it (i.e. converts it to a string).
+	 *
+	 * @param mixed $input Input to render.
+	 * @return string The rendered contents.
+	 */
+	public function findAndRender($input) {
+		if ($input === null) {
+			return null;
+		}
+
+		// For objects, try to find a renderer in the map
+		if(is_object($input)) {
+			$renderer = $this->getByClassName(get_class($input));
+			if (isset($renderer)) {
+				return $renderer->render($input);
+			}
+		}
+
+		// Fall back to the default renderer
+		return $this->defaultRenderer->render($input);
+	}
+
+	/**
+	 * Returns the appropriate renderer for a given object.
+	 *
+	 * @param mixed $object
+	 * @return RendererInterface Or null if none found.
+	 */
+	public function getByObject($object) {
+		if (!is_object($object)) {
+			return null;
+		}
+		return $this->getByClassName(get_class($object));
+	}
+
+	/**
+	 * Returns the appropriate renderer for a given class name.
+	 *
+	 * If no renderer could be found, returns NULL.
+	 *
+	 * @param string $class
+	 * @return LoggerRendererObject Or null if not found.
+	 */
+	public function getByClassName($class) {
+		for(; !empty($class); $class = get_parent_class($class)) {
+			$class = strtolower($class);
+			if(isset($this->map[$class])) {
+				return $this->map[$class];
+			}
+		}
+		return null;
+	}
+
+	/** Empties the renderer map. */
+	public function clear() {
+		$this->map = array();
+	}
+
+	/** Resets the renderer map to it's default configuration. */
+	public function reset() {
+		$this->defaultRenderer = new DefaultRenderer();
+		$this->clear();
+		$this->addRenderer('Exception', 'ExceptionRenderer');
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/RootLogger.php
----------------------------------------------------------------------
diff --git a/src/RootLogger.php b/src/RootLogger.php
new file mode 100644
index 0000000..ba7f5c3
--- /dev/null
+++ b/src/RootLogger.php
@@ -0,0 +1,69 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php;
+
+/**
+ * The root logger.
+ * @see Logger
+ */
+class RootLogger extends Logger
+{
+	/**
+	 * Constructor
+	 *
+	 * @param integer $level initial log level
+	 */
+	public function __construct(Level $level = null) {
+		parent::__construct('root');
+
+		if($level == null) {
+			$level = Level::getLevelAll();
+		}
+		$this->setLevel($level);
+	}
+
+	/**
+	 * @return Level the level
+	 */
+	public function getEffectiveLevel() {
+		return $this->getLevel();
+	}
+
+	/**
+	 * Override level setter to prevent setting the root logger's level to
+	 * null. Root logger must always have a level.
+	 *
+	 * @param Level $level
+	 */
+	public function setLevel(Level $level = null) {
+		if (isset($level)) {
+			parent::setLevel($level);
+		} else {
+			trigger_error("log4php: Cannot set RootLogger level to null.", E_USER_WARNING);
+		}
+	}
+
+	/**
+	 * Override parent setter. Root logger cannot have a parent.
+	 * @param Logger $parent
+	 */
+	public function setParent(Logger $parent) {
+		trigger_error("log4php: RootLogger cannot have a parent.", E_USER_WARNING);
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/ThrowableInformation.php
----------------------------------------------------------------------
diff --git a/src/ThrowableInformation.php b/src/ThrowableInformation.php
new file mode 100644
index 0000000..e2befeb
--- /dev/null
+++ b/src/ThrowableInformation.php
@@ -0,0 +1,67 @@
+<?php
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache\Log4php;
+
+/**
+ * The internal representation of throwables.
+ *
+ * @since 2.1
+ */
+class ThrowableInformation
+{
+	/** @var Exception Throwable to log */
+	private $throwable;
+
+	/** @var array Array of throwable messages */
+	private $throwableArray;
+
+	/**
+	 * Create a new instance
+	 *
+	 * @param $throwable - a throwable as a exception
+	 * @param $logger - Logger reference
+	 */
+	public function __construct(\Exception $throwable) {
+		$this->throwable = $throwable;
+	}
+
+	/**
+	* Return source exception
+	*
+	* @return Exception
+	*/
+	public function getThrowable() {
+		return $this->throwable;
+	}
+
+	/**
+	 * @desc Returns string representation of throwable
+	 *
+	 * @return array
+	 */
+	public function getStringRepresentation() {
+		if (!is_array($this->throwableArray)) {
+			$renderer = new Renderers\ExceptionRenderer();
+
+			$this->throwableArray = explode("\n", $renderer->render($this->throwable));
+		}
+
+		return $this->throwableArray;
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/src/assembly/src.xml
----------------------------------------------------------------------
diff --git a/src/assembly/src.xml b/src/assembly/src.xml
deleted file mode 100644
index d0dcd8d..0000000
--- a/src/assembly/src.xml
+++ /dev/null
@@ -1,49 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements.  See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License.  You may obtain a copy of the License at
-
-      http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<assembly 
-    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.1" 
-    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
-    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.1 http://maven.apache.org/xsd/assembly-1.1.1.xsd">
-	<id>src</id>
-	<formats>
-		<format>zip</format>
-		<format>tar.gz</format>
-	</formats>
-	<baseDirectory>apache-log4php-${project.version}</baseDirectory>
-	<includeSiteDirectory>false</includeSiteDirectory>
-	<fileSets>
-		<fileSet>
-			<includes>
-				<include>LICENSE</include>
-				<include>NOTICE</include>
-				<include>README</include>
-				<include>INSTALL</include>
-				<include>CHANGELOG</include>
-				<include>pom.xml</include>
-				<include>build.xml</include>
-				<include>package-config.php</include>
-				<include>package.php</include>
-				<include>src/**</include>
-			</includes>
-		</fileSet>
-		<fileSet>
-			<directory>target/site/apidocs</directory>
-			<outputDirectory>apidocs</outputDirectory>
-		</fileSet>
-	</fileSets>
-</assembly>


Mime
View raw message