Author: grobmeier
Date: Tue Aug 18 05:07:24 2009
New Revision: 805278
URL: http://svn.apache.org/viewvc?rev=805278&view=rev
Log:
sorted methodes, removed outdated method
Modified:
incubator/log4php/trunk/src/main/php/Logger.php
Modified: incubator/log4php/trunk/src/main/php/Logger.php
URL:
http://svn.apache.org/viewvc/incubator/log4php/trunk/src/main/php/Logger.php?rev=805278&r1=805277&r2=805278&view=diff
==============================================================================
--- incubator/log4php/trunk/src/main/php/Logger.php (original)
+++ incubator/log4php/trunk/src/main/php/Logger.php Tue Aug 18 05:07:24 2009
@@ -50,25 +50,6 @@
* Localization: l7dlog($priority, $key, $params, $t) : not supported
*/
class Logger {
- /**
- * Additivity is set to true by default, that is children inherit the
- * appenders of their ancestors by default.
- * @var boolean
- */
- private $additive = true;
-
- /** @var string fully qualified class name */
- private $fqcn = 'Logger';
-
- /** @var LoggerLevel The assigned level of this category. */
- private $level = null;
-
- /** @var string name of this category. */
- private $name = '';
-
- /** @var Logger The parent of this category. Null if this is the root
logger*/
- private $parent = null;
-
private static $_classes = array(
'LoggerException' => '/LoggerException.php',
'LoggerHierarchy' => '/LoggerHierarchy.php',
@@ -146,11 +127,42 @@
}
/**
+ * Additivity is set to true by default, that is children inherit the
+ * appenders of their ancestors by default.
+ * @var boolean
+ */
+ private $additive = true;
+
+ /** @var string fully qualified class name */
+ private $fqcn = 'Logger';
+
+ /** @var LoggerLevel The assigned level of this category. */
+ private $level = null;
+
+ /** @var string name of this category. */
+ private $name = '';
+
+ /** @var Logger The parent of this category. Null if this is the root
logger*/
+ private $parent = null;
+
+ /**
* @var array collection of appenders
* @see LoggerAppender
*/
private $aai = array();
+ /** the hierarchy used by log4php */
+ private static $hierarchy;
+
+ /** the configurator class name */
+ private static $configurationClass = 'LoggerConfiguratorBasic';
+
+ /** the path to the configuration file */
+ private static $configurationFile = null;
+
+ /** inidicates if log4php has already been initialized */
+ private static $initialized = false;
+
/**
* Constructor.
* @param string $name Category name
@@ -159,7 +171,21 @@
$this->name = $name;
}
- private static $hierarchy;
+ /**
+ * Return the category name.
+ * @return string
+ */
+ public function getName() {
+ return $this->name;
+ }
+
+ /**
+ * Returns the parent of this category.
+ * @return Logger
+ */
+ public function getParent() {
+ return $this->parent;
+ }
/**
* Returns the hierarchy used by this Logger.
@@ -175,44 +201,8 @@
}
return self::$hierarchy;
}
- /**
- * Add a new Appender to the list of appenders of this Category
instance.
- *
- * @param LoggerAppender $newAppender
- */
- public function addAppender($newAppender) {
- $appenderName = $newAppender->getName();
- $this->aai[$appenderName] = $newAppender;
- }
-
- /**
- * If assertion parameter is false, then logs msg as an error statement.
- *
- * @param bool $assertion
- * @param string $msg message to log
- */
- public function assertLog($assertion = true, $msg = '') {
- if($assertion == false) {
- $this->error($msg);
- }
- }
-
- /**
- * Call the appenders in the hierarchy starting at this.
- *
- * @param LoggerLoggingEvent $event
- */
- public function callAppenders($event) {
- if(count($this->aai) > 0) {
- foreach(array_keys($this->aai) as $appenderName) {
- $this->aai[$appenderName]->doAppend($event);
- }
- }
- if($this->parent != null and $this->getAdditivity()) {
- $this->parent->callAppenders($event);
- }
- }
+ /* Logging methods */
/**
* Log a message object with the DEBUG level including the caller.
*
@@ -264,12 +254,6 @@
$this->logLevel($message, LoggerLevel::getLevelFatal(),
$caller);
}
- private function logLevel($message, $level, $caller = null) {
- if($level->isGreaterOrEqual($this->getEffectiveLevel())) {
- $this->forcedLog($this->fqcn, $caller, $level,
$message);
- }
- }
-
/**
* This method creates a new logging event and logs the event without
further checks.
*
@@ -285,15 +269,149 @@
public function forcedLog($fqcn, $caller, $level, $message) {
$this->callAppenders(new LoggerLoggingEvent($fqcn, $this,
$level, $message));
}
+
+
+ /**
+ * Check whether this category is enabled for the DEBUG Level.
+ * @return boolean
+ */
+ public function isDebugEnabled() {
+ return $this->isEnabledFor(LoggerLevel::getLevelDebug());
+ }
/**
- * Get the additivity flag for this Category instance.
+ * Check whether this category is enabled for a given Level passed as
parameter.
+ *
+ * @param LoggerLevel level
* @return boolean
*/
- public function getAdditivity() {
- return $this->additive;
+ public function isEnabledFor($level) {
+ return
(bool)($level->isGreaterOrEqual($this->getEffectiveLevel()));
+ }
+
+ /**
+ * Check whether this category is enabled for the info Level.
+ * @return boolean
+ * @see LoggerLevel
+ */
+ public function isInfoEnabled() {
+ return $this->isEnabledFor(LoggerLevel::getLevelInfo());
+ }
+
+ /**
+ * This generic form is intended to be used by wrappers.
+ *
+ * @param LoggerLevel $priority a valid level
+ * @param mixed $message message
+ * @param mixed $caller caller object or caller string id
+ */
+ public function log($priority, $message, $caller = null) {
+ if($this->isEnabledFor($priority)) {
+ $this->forcedLog($this->fqcn, $caller, $priority,
$message);
+ }
}
-
+
+ /**
+ * If assertion parameter is false, then logs msg as an error statement.
+ *
+ * @param bool $assertion
+ * @param string $msg message to log
+ */
+ public function assertLog($assertion = true, $msg = '') {
+ if($assertion == false) {
+ $this->error($msg);
+ }
+ }
+
+ private function logLevel($message, $level, $caller = null) {
+ if($level->isGreaterOrEqual($this->getEffectiveLevel())) {
+ $this->forcedLog($this->fqcn, $caller, $level,
$message);
+ }
+ }
+
+ /* Factory methods */
+
+ /**
+ * Get a Logger by name (Delegate to {...@link Logger})
+ *
+ * @param string $name logger name
+ * @param LoggerFactory $factory a {...@link LoggerFactory} instance or
null
+ * @return Logger
+ * @static
+ */
+ public static function getLogger($name) {
+ if(!self::isInitialized()) {
+ self::initialize();
+ }
+ return self::getHierarchy()->getLogger($name);
+ }
+
+ /**
+ * get the Root Logger (Delegate to {...@link Logger})
+ * @return LoggerRoot
+ * @static
+ */
+ public static function getRootLogger() {
+ if(!self::isInitialized()) {
+ self::initialize();
+ }
+ return self::getHierarchy()->getRootLogger();
+ }
+
+ /* Configuration methods */
+
+ /**
+ * Add a new Appender to the list of appenders of this Category
instance.
+ *
+ * @param LoggerAppender $newAppender
+ */
+ public function addAppender($newAppender) {
+ $appenderName = $newAppender->getName();
+ $this->aai[$appenderName] = $newAppender;
+ }
+
+ /**
+ * Remove all previously added appenders from this Category instance.
+ */
+ public function removeAllAppenders() {
+ $appenderNames = array_keys($this->aai);
+ $enumAppenders = count($appenderNames);
+ for($i = 0; $i < $enumAppenders; $i++) {
+ $this->removeAppender($appenderNames[$i]);
+ }
+ }
+
+ /**
+ * Remove the appender passed as parameter form the list of appenders.
+ *
+ * @param mixed $appender can be an appender name or a {...@link
LoggerAppender} object
+ */
+ public function removeAppender($appender) {
+ if($appender instanceof LoggerAppender) {
+ $appender->close();
+ unset($this->aai[$appender->getName()]);
+ } else if (is_string($appender) and
isset($this->aai[$appender])) {
+ $this->aai[$appender]->close();
+ unset($this->aai[$appender]);
+ }
+ }
+
+ /**
+ * Call the appenders in the hierarchy starting at this.
+ *
+ * @param LoggerLoggingEvent $event
+ */
+ public function callAppenders($event) {
+ if(count($this->aai) > 0) {
+ foreach(array_keys($this->aai) as $appenderName) {
+ $this->aai[$appenderName]->doAppend($event);
+ }
+ }
+ if($this->parent != null and $this->getAdditivity()) {
+ $this->parent->callAppenders($event);
+ }
+ }
+
/**
* Get the appenders contained in this category as an array.
* @return array collection of appenders
@@ -309,7 +427,15 @@
public function getAppender($name) {
return $this->aai[$name];
}
-
+
+ /**
+ * Get the additivity flag for this Category instance.
+ * @return boolean
+ */
+ public function getAdditivity() {
+ return $this->additive;
+ }
+
/**
* Starting from this category, search the category hierarchy for a
non-null level and return it.
* @see LoggerLevel
@@ -333,18 +459,12 @@
}
/**
- * Get a Logger by name (Delegate to {...@link Logger})
- *
- * @param string $name logger name
- * @param LoggerFactory $factory a {...@link LoggerFactory} instance or
null
- * @return Logger
- * @static
+ * Set the level of this Category.
+ *
+ * @param LoggerLevel $level a level string or a level constant
*/
- public static function getLogger($name) {
- if(!self::isInitialized()) {
- self::initialize();
- }
- return self::getHierarchy()->getLogger($name);
+ public function setLevel($level) {
+ $this->level = $level;
}
/**
@@ -380,34 +500,6 @@
}
/**
- * Return the category name.
- * @return string
- */
- public function getName() {
- return $this->name;
- }
-
- /**
- * Returns the parent of this category.
- * @return Logger
- */
- public function getParent() {
- return $this->parent;
- }
-
- /**
- * get the Root Logger (Delegate to {...@link Logger})
- * @return LoggerRoot
- * @static
- */
- public static function getRootLogger() {
- if(!self::isInitialized()) {
- self::initialize();
- }
- return self::getHierarchy()->getRootLogger();
- }
-
- /**
* check if a given logger exists.
*
* @param string $name logger name
@@ -419,17 +511,6 @@
}
/**
- * Returns the LoggerHierarchy.
- *
- * @static
- * @return LoggerHierarchy
- * @deprecated
- */
- public static function getLoggerRepository() {
- return self::getHierarchy();
- }
-
- /**
* Returns an array this whole Logger instances.
*
* @static
@@ -439,6 +520,7 @@
public static function getCurrentLoggers() {
return self::getHierarchy()->getCurrentLoggers();
}
+
/**
* Is the appender passed as parameter attached to this category?
*
@@ -449,72 +531,6 @@
}
/**
- * Check whether this category is enabled for the DEBUG Level.
- * @return boolean
- */
- public function isDebugEnabled() {
- return $this->isEnabledFor(LoggerLevel::getLevelDebug());
- }
-
- /**
- * Check whether this category is enabled for a given Level passed as
parameter.
- *
- * @param LoggerLevel level
- * @return boolean
- */
- public function isEnabledFor($level) {
- return
(bool)($level->isGreaterOrEqual($this->getEffectiveLevel()));
- }
-
- /**
- * Check whether this category is enabled for the info Level.
- * @return boolean
- * @see LoggerLevel
- */
- public function isInfoEnabled() {
- return $this->isEnabledFor(LoggerLevel::getLevelInfo());
- }
-
- /**
- * This generic form is intended to be used by wrappers.
- *
- * @param LoggerLevel $priority a valid level
- * @param mixed $message message
- * @param mixed $caller caller object or caller string id
- */
- public function log($priority, $message, $caller = null) {
- if($this->isEnabledFor($priority)) {
- $this->forcedLog($this->fqcn, $caller, $priority,
$message);
- }
- }
-
- /**
- * Remove all previously added appenders from this Category instance.
- */
- public function removeAllAppenders() {
- $appenderNames = array_keys($this->aai);
- $enumAppenders = count($appenderNames);
- for($i = 0; $i < $enumAppenders; $i++) {
- $this->removeAppender($appenderNames[$i]);
- }
- }
-
- /**
- * Remove the appender passed as parameter form the list of appenders.
- *
- * @param mixed $appender can be an appender name or a {...@link
LoggerAppender} object
- */
- public function removeAppender($appender) {
- if($appender instanceof LoggerAppender) {
- $appender->close();
- unset($this->aai[$appender->getName()]);
- } else if (is_string($appender) and
isset($this->aai[$appender])) {
- $this->aai[$appender]->close();
- unset($this->aai[$appender]);
- }
- }
-
- /**
* Set the additivity flag for this Category instance.
*
* @param boolean $additive
@@ -524,26 +540,12 @@
}
/**
- * Set the level of this Category.
- *
- * @param LoggerLevel $level a level string or a level constant
- */
- public function setLevel($level) {
- $this->level = $level;
- }
-
- /**
* Sets the parent logger of this logger
*/
public function setParent(Logger $logger) {
$this->parent = $logger;
}
- /** the configurator class name */
- private static $configurationClass = 'LoggerConfiguratorBasic';
- /** the path to the configuration file */
- private static $configurationFile = null;
-
/**
* Configures Log4PHP.
* This method needs to be called before the first logging event
@@ -598,8 +600,6 @@
return self::$configurationFile;
}
- private static $initialized = false;
-
/**
* Returns, true, if the log4php framework is already initialized
*/