logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ihabu...@apache.org
Subject svn commit: r1201417 - in /logging/log4php/trunk/src/main/php: LoggerConfigurator.php configurators/LoggerConfigurationAdapterXML.php
Date Sun, 13 Nov 2011 09:45:43 GMT
Author: ihabunek
Date: Sun Nov 13 09:45:43 2011
New Revision: 1201417

URL: http://svn.apache.org/viewvc?rev=1201417&view=rev
Log:
LOG4PHP-152: Improved error reporting for configurator.

Modified:
    logging/log4php/trunk/src/main/php/LoggerConfigurator.php
    logging/log4php/trunk/src/main/php/configurators/LoggerConfigurationAdapterXML.php

Modified: logging/log4php/trunk/src/main/php/LoggerConfigurator.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/LoggerConfigurator.php?rev=1201417&r1=1201416&r2=1201417&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/LoggerConfigurator.php (original)
+++ logging/log4php/trunk/src/main/php/LoggerConfigurator.php Sun Nov 13 09:45:43 2011
@@ -235,21 +235,25 @@ class LoggerConfigurator
 		// TODO: add this check to other places where it might be useful
 		if (!is_array($config)) {
 			$type = gettype($config);
-			$this->warn("Invalid configuration provided for [$name] appender. Expected an array,
found <$type>. Skipping appender definition.");
+			$this->warn("Invalid configuration provided for appender [$name]. Expected an array,
found <$type>. Skipping appender definition.");
 			return;
 		}
 		
 		// Parse appender class
 		$class = $config['class'];
+		if (empty($class)) {
+			$this->warn("No class given for appender [$name]. Skipping appender definition.");
+			return;
+		}
 		if (!class_exists($class)) {
-			$this->warn("Class [$class] does not exist. Skipping appender [$name].");
+			$this->warn("Invalid class [$class] given for appender [$name]. Class does not exist.
Skipping appender definition.");
 			return;
 		}
 		
 		// Instantiate the appender
 		$appender = new $class($name);
 		if (!($appender instanceof LoggerAppender)) {
-			$this->warn("[$class] is not a valid appender class. Skipping appender [$name].");
+			$this->warn("Invalid class [$class] given for appender [$name]. Not a valid LoggerAppender
class. Skipping appender definition.");
 			return;
 		}
 		
@@ -294,6 +298,10 @@ class LoggerConfigurator
 	private function createAppenderLayout(LoggerAppender $appender, $config) {
 		$name = $appender->getName();
 		$class = $config['class'];
+		if (empty($class)) {
+			$this->warn("Layout class not specified for appender [$name]. Reverting to default
layout.");
+			return;
+		}
 		if (!class_exists($class)) {
 			$this->warn("Nonexistant layout class [$class] specified for appender [$name]. Reverting
to default layout.");
 			return;

Modified: logging/log4php/trunk/src/main/php/configurators/LoggerConfigurationAdapterXML.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/configurators/LoggerConfigurationAdapterXML.php?rev=1201417&r1=1201416&r2=1201417&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/configurators/LoggerConfigurationAdapterXML.php (original)
+++ logging/log4php/trunk/src/main/php/configurators/LoggerConfigurationAdapterXML.php Sun
Nov 13 09:45:43 2011
@@ -96,7 +96,11 @@ class LoggerConfigurationAdapterXML impl
 	/** Parses an <appender> node. */
 	private function parseAppender(SimpleXMLElement $node) {
 		$name = $this->getAttributeValue($node, 'name');
-
+		if (empty($name)) {
+			$this->warn("An <appender> node is missing the required 'name' attribute. Skipping
appender definition.");
+			return;
+		}
+		
 		$appender = array();
 		$appender['class'] = $this->getAttributeValue($node, 'class');
 		
@@ -136,7 +140,7 @@ class LoggerConfigurationAdapterXML impl
 
 		foreach($paramsNode->param as $paramNode) {
 			if (empty($paramNode['name'])) {
-				$this->warn("Found parameter node without a name. Skipping parameter.");
+				$this->warn("A <param> node is missing the required 'name' attribute. Skipping
parameter.");
 				continue;
 			}
 			
@@ -169,14 +173,12 @@ class LoggerConfigurationAdapterXML impl
 	private function parseLogger(SimpleXMLElement $node) {
 		$logger = array();
 		
-		// Check logger name exists (mandatory because it is used as the array key)
-		if (empty($node['name'])) {
-			$this->warn("Found logger without a 'name' attribute. All loggers must be named. Skipping.");
+		$name = $this->getAttributeValue($node, 'name');
+		if (empty($name)) {
+			$this->warn("A <logger> node is missing the required 'name' attribute. Skipping
logger definition.");
 			return;
 		}
 		
-		$name = (string) $node['name'];
-		
 		if (isset($node->level)) {
 			$logger['level'] = $this->getAttributeValue($node->level, 'value');
 		}
@@ -232,8 +234,7 @@ class LoggerConfigurationAdapterXML impl
 	// ******************************************
 	
 	private function getAttributeValue(SimpleXMLElement $node, $name) {
-		$attrs = $node->attributes();
-		return isset($attrs[$name]) ? (string) $attrs[$name] : null;
+		return isset($node[$name]) ? (string) $node[$name] : null;
 	}
 	
 	private function warn($message) {



Mime
View raw message