Permalink
Browse files

Added latest svn checkout of log4php

  • Loading branch information...
1 parent 7b5634e commit 357ddee78bc921171a9634f4f10f84ceb5126e5d Vladimir Gorej committed Dec 21, 2010
@@ -26,7 +26,7 @@
*/
class LoggerAppenderPool {
/* Appender Pool */
- public static $appenderPool = null;
+ public static $appenderPool = array();
/**
*
@@ -52,4 +52,9 @@ public static function getAppenderFromPool($name, $class = '') {
}
return null;
}
-}
+
+ public static function clear()
+ {
+ self::$appenderPool = array();
+ }
+}
@@ -44,7 +44,7 @@
* to the provision node. Other descendants of the same ancestor add
* themselves to the previously created provision node.</p>
*
- * @version $Revision: 822448 $
+ * @version $Revision: 998428 $
* @package log4php
*/
/*
@@ -205,6 +205,7 @@ public function resetConfiguration() {
$loggers[$i]->removeAllAppenders();
}
$this->rendererMap->clear();
+ LoggerAppenderPool::clear();
}
/**
@@ -27,7 +27,7 @@
* <p>The <i>LoggerLevel</i> class may be subclassed to define a larger
* level set.</p>
*
- * @version $Revision: 912120 $
+ * @version $Revision: 998420 $
* @package log4php
* @since 0.5
*/
@@ -213,13 +213,20 @@ public function isGreaterOrEqual($r) {
}
/**
- * Returns the string representation of this priority.
+ * Returns the string representation of this level.
* @return string
- * @final
*/
public function toString() {
return $this->levelStr;
}
+
+ /**
+ * Returns the string representation of this level.
+ * @return string
+ */
+ public function __toString() {
+ return $this->toString();
+ }
/**
* Returns the integer representation of this level.
@@ -21,7 +21,7 @@
/**
* The internal representation of logging event.
*
- * @version $Revision: 955838 $
+ * @version $Revision: 998456 $
* @package log4php
*/
class LoggerLoggingEvent {
@@ -259,7 +259,7 @@ public function getMessage() {
public function getNDC() {
if($this->ndcLookupRequired) {
$this->ndcLookupRequired = false;
- $this->ndc = implode(' ', LoggerNDC::get());
+ $this->ndc = LoggerNDC::get();
}
return $this->ndc;
}
@@ -19,11 +19,6 @@
*/
/**
- * This is the global repository of user mappings
- */
-$GLOBALS['log4php.LoggerMDC.ht'] = array();
-
-/**
* The LoggerMDC class provides <i>mapped diagnostic contexts</i>.
*
* <p>A <i>Mapped Diagnostic Context</i>, or
@@ -50,11 +45,17 @@
* 2009-09-13 18:48:28 DEBUG root knut: Testing MDC in src/examples/php/mdc.php at 23
* </pre>
*
- * @version $Revision: 883114 $
+ * @version $Revision: 998444 $
* @since 0.3
* @package log4php
*/
class LoggerMDC {
+
+ /**
+ * This is the repository of user mappings
+ */
+ private static $map = array();
+
/**
* Put a context value as identified with the key parameter into the current thread's
* context map.
@@ -69,7 +70,7 @@ class LoggerMDC {
* @static
*/
public static function put($key, $value) {
- $GLOBALS['log4php.LoggerMDC.ht'][$key] = $value;
+ self::$map[$key] = $value;
}
/**
@@ -81,20 +82,22 @@ public static function put($key, $value) {
*
* <p>This method has no side effects.</p>
*
- * @param string $key
- * @return string
+ * @param string $key the key
+ * @return string the context or an empty string if no context found
+ * for given key
* @static
*/
public static function get($key) {
if(!empty($key)) {
if(strpos($key, 'server.') === 0) {
$varName = substr($key, 7);
- return @$_SERVER[$varName];
+ return isset($_SERVER[$varName]) ? $_SERVER[$varName] : '';
} else if(strpos($key, 'env.') === 0) {
$varName = substr($key, 4);
- return @$_ENV[$varName];
- } else if (isset($GLOBALS['log4php.LoggerMDC.ht'][$key])) {
- return $GLOBALS['log4php.LoggerMDC.ht'][$key];
+ $value = getenv($varName);
+ return ($value !== false) ? $value : '';
+ } else {
+ return isset(self::$map[$key]) ? self::$map[$key] : '';
}
}
return '';
@@ -103,14 +106,12 @@ public static function get($key) {
/**
* Remove the the context identified by the key parameter.
*
- * It only affects user mappings.
+ * It only affects user mappings, not $_ENV or $_SERVER.
*
- * @param string $key
- * @return string
+ * @param string $key the key to be removed
* @static
*/
public static function remove($key) {
- unset($GLOBALS['log4php.LoggerMDC.ht'][$key]);
+ unset(self::$map[$key]);
}
-
}
@@ -18,12 +18,6 @@
* @package log4php
*/
-
-/**
- * This is the global repository of NDC stack
- */
-$GLOBALS['log4php.LoggerNDC.ht'] = array();
-
/**
* The NDC class implements <i>nested diagnostic contexts</i>.
*
@@ -95,12 +89,15 @@
* 2009-09-13 19:04:27 DEBUG root : back and waiting for new connections in src/examples/php/ndc.php at 29
* </pre>
*
- * @version $Revision: 883114 $
+ * @version $Revision: 998456 $
* @package log4php
* @since 0.3
*/
class LoggerNDC {
- const HT_SIZE = 7;
+
+ /** 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
@@ -109,10 +106,10 @@ class LoggerNDC {
* <p>This method is equivalent to calling the {@link setMaxDepth()}
* method with a zero <var>maxDepth</var> argument.
*
- * @static
+ * @static
*/
public static function clear() {
- $GLOBALS['log4php.LoggerNDC.ht'] = array();
+ self::$stack = array();
}
/**
@@ -121,10 +118,7 @@ public static function clear() {
* @return array
*/
public static function get() {
- if(!array_key_exists('log4php.LoggerNDC.ht', $GLOBALS)) {
- LoggerNDC::clear();
- }
- return $GLOBALS['log4php.LoggerNDC.ht'];
+ return implode(' ', self::$stack);
}
/**
@@ -135,7 +129,7 @@ public static function get() {
* @static
*/
public static function getDepth() {
- return count($GLOBALS['log4php.LoggerNDC.ht']);
+ return count(self::$stack);
}
/**
@@ -149,8 +143,8 @@ public static function getDepth() {
* @static
*/
public static function pop() {
- if(count($GLOBALS['log4php.LoggerNDC.ht']) > 0) {
- return array_pop($GLOBALS['log4php.LoggerNDC.ht']);
+ if(count(self::$stack) > 0) {
+ return array_pop(self::$stack);
} else {
return '';
}
@@ -166,8 +160,8 @@ public static function pop() {
* @static
*/
public static function peek(){
- if(count($GLOBALS['log4php.LoggerNDC.ht']) > 0) {
- return end($GLOBALS['log4php.LoggerNDC.ht']);
+ if(count(self::$stack) > 0) {
+ return end(self::$stack);
} else {
return '';
}
@@ -183,7 +177,7 @@ public static function peek(){
* @static
*/
public static function push($message) {
- array_push($GLOBALS['log4php.LoggerNDC.ht'], (string)$message);
+ array_push(self::$stack, (string)$message);
}
/**
@@ -211,11 +205,8 @@ public static function remove() {
*/
public static function setMaxDepth($maxDepth) {
$maxDepth = (int)$maxDepth;
- if($maxDepth <= self::HT_SIZE) {
- if(LoggerNDC::getDepth() > $maxDepth) {
- $GLOBALS['log4php.LoggerNDC.ht'] = array_slice($GLOBALS['log4php.LoggerNDC.ht'], $maxDepth);
- }
+ if(LoggerNDC::getDepth() > $maxDepth) {
+ self::$stack = array_slice(self::$stack, 0, $maxDepth);
}
}
-
}
@@ -42,7 +42,7 @@
* 0 8318 INFO root Hello World!
* </pre>
*
- * @version $Revision: 883108 $
+ * @version $Revision: 998420 $
* @package log4php
* @subpackage layouts
*/
@@ -145,15 +145,11 @@ public function format(LoggerLoggingEvent $event) {
$level = $event->getLevel();
if ($level->equals(LoggerLevel::getLevelDebug())) {
- $sbuf .= "<font color=\"#339933\">";
- $sbuf .= $level->toString();
- $sbuf .= "</font>";
+ $sbuf .= "<font color=\"#339933\">$level</font>";
} else if ($level->equals(LoggerLevel::getLevelWarn())) {
- $sbuf .= "<font color=\"#993300\"><strong>";
- $sbuf .= $level->toString();
- $sbuf .= "</strong></font>";
+ $sbuf .= "<font color=\"#993300\"><strong>$level</strong></font>";
} else {
- $sbuf .= $level->toString();
+ $sbuf .= $level;
}
$sbuf .= "</td>" . PHP_EOL;
@@ -34,7 +34,7 @@
*
* <samp>INFO - Hello World!</samp>
*
- * @version $Revision: 883108 $
+ * @version $Revision: 998420 $
* @package log4php
* @subpackage layouts
*/
@@ -56,6 +56,7 @@ public function __construct() {
*/
public function format(LoggerLoggingEvent $event) {
$level = $event->getLevel();
- return $level->toString() . ' - ' . $event->getRenderedMessage(). PHP_EOL;
+ $message = $event->getRenderedMessage();
+ return "$level - $message" . PHP_EOL;
}
}
@@ -44,7 +44,7 @@
* The above would print:<br>
* <samp>02:28 [13714] INFO root - Hello World!</samp>
*
- * @version $Revision: 883108 $
+ * @version $Revision: 998420 $
* @package log4php
* @subpackage layouts
*/
@@ -190,7 +190,7 @@ public function format(LoggerLoggingEvent $event) {
}
$level = $event->getLevel();
- $format .= $level->toString().' ';
+ $format .= $level.' ';
if($this->categoryPrefixing) {
$format .= $event->getLoggerName().' ';

0 comments on commit 357ddee

Please sign in to comment.