Example #1
0
 /**
  * @inheritdoc
  */
 public function setLevel($level)
 {
     try {
         $this->_log4php->setLevel($this->_convertESAPILeveltoLoggerLevel($level));
     } catch (Exception $e) {
         $this->error(Logger::SECURITY, false, 'IllegalArgumentException', $e);
     }
 }
Example #2
0
 /**
  * Override level setter to prevent setting the root logger's level to 
  * null. Root logger must always have a level.
  * 
  * @param LoggerLevel $level
  */
 public function setLevel(LoggerLevel $level = null)
 {
     if (isset($level)) {
         parent::setLevel($level);
     } else {
         trigger_error("log4php: Cannot set LoggerRoot level to null.", E_USER_WARNING);
     }
 }
Example #3
0
 /**
  * Setting a null value to the level of the root category may have catastrophic results.
  * @param LoggerLevel $level
  */
 public function setLevel($level)
 {
     if ($level != null) {
         parent::setLevel($level);
     }
 }
Example #4
0
    }
    public function getLevelName($level)
    {
        return $this->logLevels[$level];
    }
}
// testing
if (isset($_SERVER["argv"][1]) && $_SERVER["argv"][1] == "__main__") {
    $logger = new Logger();
    for ($i = 0; $i < 6; $i++) {
        $logger->setLevel($i);
        error_log("############## Level now: " . $i);
        $logger->debug("");
        $logger->info("");
        $logger->notice("");
        $logger->warn("");
        $logger->error("");
        $logger->critical("");
    }
    error_log("############# With Level Names");
    for ($i = 0; $i < 6; $i++) {
        $logger->setLevel($logger->getLevelName($i));
        error_log("############## Level now: " . $logger->getLevelName($i));
        $logger->debug("");
        $logger->info("", __FILE__, __LINE__);
        $logger->notice("");
        $logger->warn("");
        $logger->error("");
        $logger->critical("");
    }
}
 /**
  * This method must work for the root category as well.
  *
  * @param array $props array of properties
  * @param Logger $logger
  * @param string $optionKey
  * @param string $loggerName
  * @param string $value
  * @return Logger
  */
 private function parseCategory($props, Logger $logger, $optionKey, $loggerName, $value)
 {
     // We must skip over ',' but not white space
     $st = explode(',', $value);
     // If value is not in the form ", appender.." or "", then we should set
     // the level of the loggeregory.
     if (!(empty($value) || @$value[0] == ',')) {
         // just to be on the safe side...
         if (count($st) == 0) {
             return;
         }
         $levelStr = current($st);
         // If the level value is inherited, set category level value to
         // null. We also check that the user has not specified inherited for the
         // root category.
         if ('INHERITED' == strtoupper($levelStr) || 'NULL' == strtoupper($levelStr)) {
             if ($loggerName == self::INTERNAL_ROOT_NAME) {
                 // TODO: throw exception?	"The root logger cannot be set to null."
             } else {
                 $logger->setLevel(null);
             }
         } else {
             $logger->setLevel(LoggerOptionConverter::toLevel($levelStr, LoggerLevel::getLevelDebug()));
         }
     }
     // TODO: removing should be done by the logger, if necessary and wanted
     // $logger->removeAllAppenders();
     while ($appenderName = next($st)) {
         $appenderName = trim($appenderName);
         if (empty($appenderName)) {
             continue;
         }
         $appender = $this->parseAppender($props, $appenderName);
         if ($appender !== null) {
             $logger->addAppender($appender);
         }
     }
 }
 /**
  * Configures a logger. 
  * 
  * @param Logger $logger The logger to configure
  * @param array $config Logger configuration options.
  */
 private function configureLogger(Logger $logger, $config)
 {
     $loggerName = $logger->getName();
     // Set logger level
     if (isset($config['level'])) {
         $level = LoggerLevel::toLevel($config['level']);
         if (isset($level)) {
             $logger->setLevel($level);
         } else {
             $default = $logger->getLevel();
             $this->warn("Invalid level value [{$config['level']}] specified for logger [{$loggerName}]. Ignoring level definition.");
         }
     }
     // Link appenders to logger
     if (isset($config['appenders'])) {
         foreach ($config['appenders'] as $appenderName) {
             if (isset($this->appenders[$appenderName])) {
                 $logger->addAppender($this->appenders[$appenderName]);
             } else {
                 $this->warn("Nonexistnant appender [{$appenderName}] linked to logger [{$loggerName}].");
             }
         }
     }
     // Set logger additivity
     if (isset($config['additivity'])) {
         $additivity = LoggerOptionConverter::toBoolean($config['additivity'], null);
         if (is_bool($additivity)) {
             $logger->setAdditivity($additivity);
         } else {
             $this->warn("Invalid additivity value [{$config['additivity']}] specified for logger [{$loggerName}]. Ignoring additivity setting.");
         }
     }
 }