logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ihabu...@apache.org
Subject svn commit: r1308825 - /logging/log4php/trunk/src/main/php/pattern/LoggerPatternConverterLogger.php
Date Tue, 03 Apr 2012 11:37:29 GMT
Author: ihabunek
Date: Tue Apr  3 11:37:29 2012
New Revision: 1308825

URL: http://svn.apache.org/viewvc?rev=1308825&view=rev
Log:
Moved shortenClassName implementation to LoggerUtils so that it can be used from elsewhere.

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

Modified: logging/log4php/trunk/src/main/php/pattern/LoggerPatternConverterLogger.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/pattern/LoggerPatternConverterLogger.php?rev=1308825&r1=1308824&r2=1308825&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/pattern/LoggerPatternConverterLogger.php (original)
+++ logging/log4php/trunk/src/main/php/pattern/LoggerPatternConverterLogger.php Tue Apr  3
11:37:29 2012
@@ -49,9 +49,9 @@ class LoggerPatternConverterLogger exten
 
 			// If length is set return shortened logger name 
 			if (isset($this->length)) {
-				$this->cache[$name] = $this->shorten($name, $this->length);
+				$this->cache[$name] = LoggerUtils::shortenClassName($name, $this->length);
 			} 
-			 
+			
 			// If no length is specified return full logger name
 			else {
 				$this->cache[$name] = $name;
@@ -60,55 +60,4 @@ class LoggerPatternConverterLogger exten
 		
 		return $this->cache[$name];
 	}
-	
-	/** 
-	 * Attempts to shorten the given name to the desired length by trimming 
-	 * name fragments. See docs for examples.
-	 */
-	private function shorten($name, $length) {
-	
-		$currentLength = strlen($name);
-	
-		// Check if any shortening is required
-		if ($currentLength <= $length) {
-			return $name;
-		}
-	
-		// Split name into fragments
-		$name = str_replace('.', '\\', $name);
-		$name = trim($name, ' \\');
-		$fragments = explode('\\', $name);
-		$count = count($fragments);
-	
-		// If the name splits to only one fragment, then it cannot be shortened
-		if ($count == 1) {
-			return $name;
-		}
-		
-		foreach($fragments as $key => &$fragment) {
-	
-			// Never shorten last fragment
-			if ($key == $count - 1) {
-				break;
-			}
-	
-			// Check for empty fragments (shouldn't happen but it's possible)
-			$fragLen = strlen($fragment);
-			if ($fragLen <= 1) {
-				continue;
-			}
-	
-			// Shorten fragment to one character and check if total length satisfactory
-			$fragment = substr($fragment, 0, 1);
-			$currentLength = $currentLength - $fragLen + 1;
-	
-			if ($currentLength <= $length) {
-				break;
-			}
-		}
-		unset($fragment);
-	
-		return implode('\\', $fragments);
-	}
-	
 }



Mime
View raw message