logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ihabu...@apache.org
Subject svn commit: r1308829 - /logging/log4php/trunk/src/main/php/pattern/LoggerPatternConverterClass.php
Date Tue, 03 Apr 2012 11:44:39 GMT
Author: ihabunek
Date: Tue Apr  3 11:44:38 2012
New Revision: 1308829

URL: http://svn.apache.org/viewvc?rev=1308829&view=rev
Log:
Added shortening of class names for the %class pattern converter.

Modified:
    logging/log4php/trunk/src/main/php/pattern/LoggerPatternConverterClass.php

Modified: logging/log4php/trunk/src/main/php/pattern/LoggerPatternConverterClass.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/pattern/LoggerPatternConverterClass.php?rev=1308829&r1=1308828&r2=1308829&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/pattern/LoggerPatternConverterClass.php (original)
+++ logging/log4php/trunk/src/main/php/pattern/LoggerPatternConverterClass.php Tue Apr  3
11:44:38 2012
@@ -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



Mime
View raw message