logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ihabu...@apache.org
Subject svn commit: r1241439 - in /logging/log4php/trunk/src: changes/changes.xml main/php/Logger.php site/xdoc/docs/configuration.xml
Date Tue, 07 Feb 2012 12:17:21 GMT
Author: ihabunek
Date: Tue Feb  7 12:17:21 2012
New Revision: 1241439

URL: http://svn.apache.org/viewvc?rev=1241439&view=rev
Log:
LOG4PHP-168: Fixed a bug which prevented configuration by passing a LoggerConfigurator instance.

Modified:
    logging/log4php/trunk/src/changes/changes.xml
    logging/log4php/trunk/src/main/php/Logger.php
    logging/log4php/trunk/src/site/xdoc/docs/configuration.xml

Modified: logging/log4php/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/changes/changes.xml?rev=1241439&r1=1241438&r2=1241439&view=diff
==============================================================================
--- logging/log4php/trunk/src/changes/changes.xml (original)
+++ logging/log4php/trunk/src/changes/changes.xml Tue Feb  7 12:17:21 2012
@@ -21,6 +21,7 @@
 	</properties>
 	<body>
 	    <release version="2.2.1-SNAPSHOT" date="SVN">
+	        <action date="2011-02-07" type="fix" issue="LOG4PHP-168" dev="Ivan Habunek">Fixed
a bug which prevented configuration by passing a LoggerConfigurator instance.</action>
 	    	<action date="2012-01-29" type="fix" issue="LOG4PHP-167" dev="Ivan Habunek">Fixed
a bug which prevented parsing of INI configuration files when using PHP 5.2.x.</action>
 	        <action date="2011-12-22" type="update" issue="LOG4PHP-166" dev="Ivan Habunek"
due-to="David Hilowitz" due-to-email="dhilowitz at gmail dot com">Added connection timeout
parameter to MongoDB appender.</action>
 	    </release>

Modified: logging/log4php/trunk/src/main/php/Logger.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/Logger.php?rev=1241439&r1=1241438&r2=1241439&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/Logger.php (original)
+++ logging/log4php/trunk/src/main/php/Logger.php Tue Feb  7 12:17:21 2012
@@ -506,13 +506,14 @@ class Logger {
 	 * @param string|array $configuration Either a path to the configuration
 	 *   file, or a configuration array.
 	 *   
-	 * @param mixed $configuratorClass A custom configurator class: either a 
-	 * class name (string), or an object which implements LoggerConfigurator
-	 * interface. If left empty, the default configurator will be used. 
+	 * @param string|LoggerConfigurator $configurator A custom 
+	 * configurator class: either a class name (string), or an object which 
+	 * implements the LoggerConfigurator interface. If left empty, the default
+	 * configurator implementation will be used. 
 	 */
-	public static function configure($configuration = null, $configuratorClass = null) {
+	public static function configure($configuration = null, $configurator = null) {
 		self::resetConfiguration();
-		$configurator = self::getConfigurator($configuratorClass);
+		$configurator = self::getConfigurator($configurator);
 		$configurator->configure(self::getHierarchy(), $configuration);
 		self::$initialized = true;
 	}
@@ -522,26 +523,41 @@ class Logger {
 	 * configurator class. If no class is given, returns an instance of
 	 * the default configurator.
 	 * 
-	 * @param string $configuratorClass The configurator class.
+	 * @param string|LoggerConfigurator $configurator The configurator class 
+	 * or LoggerConfigurator instance.
 	 */
-	private static function getConfigurator($configuratorClass = null) {
-		if (empty($configuratorClass)) {
+	private static function getConfigurator($configurator = null) {
+		if ($configurator === null) {
 			return new LoggerConfiguratorDefault();
 		}
 		
-		if (!class_exists($configuratorClass)) {
-			$this->warn("Specified configurator class [$configuratorClass] does not exist. Reverting
to default configurator.");
-			return new LoggerConfiguratorDefault();
+		if (is_object($configurator)) {
+			if ($configurator instanceof LoggerConfigurator) {
+				return $configurator;
+			} else {
+				trigger_error("log4php: Given configurator object [$configurator] does not implement
the LoggerConfigurator interface. Reverting to default configurator.", E_USER_WARNING);
+				return new LoggerConfiguratorDefault();
+			}
 		}
 		
-		$configurator = new $configuratorClass();
+		if (is_string($configurator)) {
+			if (!class_exists($configurator)) {
+				trigger_error("log4php: Specified configurator class [$configurator] does not exist.
Reverting to default configurator.", E_USER_WARNING);
+				return new LoggerConfiguratorDefault();
+			}
 			
-		if (!($configurator instanceof LoggerConfigurator)) {
-			$this->warn("Specified configurator class [$configuratorClass] does not implement the
LoggerConfigurator interface. Reverting to default configurator.");
-			return new LoggerConfiguratorDefault();
+			$instance = new $configurator();
+				
+			if (!($instance instanceof LoggerConfigurator)) {
+				trigger_error("log4php: Specified configurator class [$configurator] does not implement
the LoggerConfigurator interface. Reverting to default configurator.", E_USER_WARNING);
+				return new LoggerConfiguratorDefault();
+			}
+			
+			return $instance;
 		}
 		
-		return $configurator;
+		trigger_error("log4php: Invalid configurator specified. Expected either a string or a LoggerConfigurator
instance. Reverting to default configurator.", E_USER_WARNING);
+		return new LoggerConfiguratorDefault();
 	}
 	
 	/**

Modified: logging/log4php/trunk/src/site/xdoc/docs/configuration.xml
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/site/xdoc/docs/configuration.xml?rev=1241439&r1=1241438&r2=1241439&view=diff
==============================================================================
--- logging/log4php/trunk/src/site/xdoc/docs/configuration.xml (original)
+++ logging/log4php/trunk/src/site/xdoc/docs/configuration.xml Tue Feb  7 12:17:21 2012
@@ -248,20 +248,23 @@ class MyConfigurator implements LoggerCo
 }
 </pre>
 
-				<p>To use the configurator, pass it as a second parameter to <code>Logger::configure()</code>

-				(either the name of the class as a string or an instance).</p>
+				<p>To use the configurator, pass it as a second parameter to <code>Logger::configure()</code>
(either 
+				    the name of the class as a string or an instance). Any value passed as <code>$configuration</code>
+				    will be available in the configure() method of the LoggerConfigurator as <code>$input</code>.</p>
 
-<pre class="prettyprint">
-Logger::configure(null, 'MyConfigurator');
+<pre class="prettyprint linenums">
+// User defined configuration (optional) 
+$configuration = array(
+    'foo' => 1,
+    'bar' => 2
+);
 
-$log = Logger::getRootLogger();
-$log->trace('one');
-$log->debug('two');
-$log->info('three');
-$log->warn('four');
-$log->error('five');
-</pre>
+// Passing the configurator as string
+Logger::configure($configuration, 'MyConfigurator');
 
+// Passing the configurator as an instance
+Logger::configure($configuration, new MyConfigurator());
+</pre>
 				<div class="alert-message block-message warn">
 					<p><strong>Note: </strong>Always call <code>activateOptions()</code>
on all appenders, filters and layouts after setting
 					their configuration parameters. Otherwise, the configuration may not be properly activated.</p>



Mime
View raw message