From commits-return-458-apmail-logging-commits-archive=logging.apache.org@logging.apache.org Tue Feb 7 12:17:43 2012 Return-Path: X-Original-To: apmail-logging-commits-archive@minotaur.apache.org Delivered-To: apmail-logging-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A4E039077 for ; Tue, 7 Feb 2012 12:17:43 +0000 (UTC) Received: (qmail 8417 invoked by uid 500); 7 Feb 2012 12:17:43 -0000 Delivered-To: apmail-logging-commits-archive@logging.apache.org Received: (qmail 8391 invoked by uid 500); 7 Feb 2012 12:17:43 -0000 Mailing-List: contact commits-help@logging.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@logging.apache.org Delivered-To: mailing list commits@logging.apache.org Received: (qmail 8384 invoked by uid 99); 7 Feb 2012 12:17:42 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Feb 2012 12:17:42 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Feb 2012 12:17:41 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 9B7BC23888CD; Tue, 7 Feb 2012 12:17:21 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@logging.apache.org From: ihabunek@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120207121721.9B7BC23888CD@eris.apache.org> 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 @@ + Fixed a bug which prevented configuration by passing a LoggerConfigurator instance. Fixed a bug which prevented parsing of INI configuration files when using PHP 5.2.x. Added connection timeout parameter to MongoDB appender. 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 } -

To use the configurator, pass it as a second parameter to Logger::configure() - (either the name of the class as a string or an instance).

+

To use the configurator, pass it as a second parameter to Logger::configure() (either + the name of the class as a string or an instance). Any value passed as $configuration + will be available in the configure() method of the LoggerConfigurator as $input.

-
-Logger::configure(null, 'MyConfigurator');
+
+// 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');
-
+// Passing the configurator as string +Logger::configure($configuration, 'MyConfigurator'); +// Passing the configurator as an instance +Logger::configure($configuration, new MyConfigurator()); +

Note: Always call activateOptions() on all appenders, filters and layouts after setting their configuration parameters. Otherwise, the configuration may not be properly activated.