Added shortening of class names for the %class pattern converter.

git-svn-id: https://svn.apache.org/repos/asf/logging/log4php/trunk@1308829 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/php/pattern/LoggerPatternConverterClass.php b/src/main/php/pattern/LoggerPatternConverterClass.php
index a43b0f3..03957b8 100644
--- a/src/main/php/pattern/LoggerPatternConverterClass.php
+++ b/src/main/php/pattern/LoggerPatternConverterClass.php
@@ -27,8 +27,36 @@
  */

 class LoggerPatternConverterClass extends LoggerPatternConverter {

 

+	/** 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(LoggerLoggingEvent $event) {

-		return $event->getLocationInformation()->getClassName();

+		$name = $event->getLocationInformation()->getClassName();

+	

+		if (!isset($this->cache[$name])) {

+	

+			// If length is set return shortened class name

+			if (isset($this->length)) {

+				$this->cache[$name] = LoggerUtils::shortenClassName($name, $this->length);

+			}

+				

+			// If no length is specified return the full class name

+			else {

+				$this->cache[$name] = $name;

+			}

+		}

+	

+		return $this->cache[$name];

 	}

 }

  
\ No newline at end of file