/**
  * 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);
     }
 }
Beispiel #2
0
 public function getLogger($payment)
 {
     \TPLogger::configure($this->config);
     if ($this->php_version != null) {
         \LoggerMDC::put('php_version', $this->php_version);
     } else {
         throw new \Exception("Logger Configuracion incompleta");
     }
     if ($this->commerce_version != null) {
         \LoggerMDC::put('commerce_version', $this->commerce_version);
     } else {
         throw new \Exception("Logger Configuracion incompleta");
     }
     if ($this->plugin_version != null) {
         \LoggerMDC::put('plugin_version', $this->plugin_version);
     } else {
         throw new \Exception("Logger Configuracion incompleta");
     }
     if ($payment) {
         if ($this->end_point != null) {
             \LoggerMDC::put('end_point', $this->end_point);
         } else {
             throw new \Exception("Logger Configuracion incompleta");
         }
         if ($this->customer != null) {
             \LoggerMDC::put('customer', $this->customer);
         } else {
             throw new \Exception("Logger Configuracion incompleta");
         }
         if ($this->order != null) {
             \LoggerMDC::put('order', $this->order);
         } else {
             throw new \Exception("Logger Configuracion incompleta");
         }
     }
     if ($payment) {
         return \TPLogger::getLogger("todopagopayment");
     }
     return \TPLogger::getLogger("todopagoadmin");
 }
Beispiel #3
0
 /**
  * Configures log4php.
  * 
  * This method needs to be called before the first logging event has 
  * occured. If this method is not called before then the default
  * configuration will be used.
  *
  * @param string|array $configuration Either a path to the configuration
  *   file, or a configuration array.
  *   
  * @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, $configurator = null)
 {
     self::resetConfiguration();
     $configurator = self::getConfigurator($configurator);
     $configurator->configure(self::getHierarchy(), $configuration);
     self::$initialized = true;
 }
 /**
  * Returns a named logger instance logger. If it doesn't exist, one is created.
  * 
  * @param string $name TPLogger name
  * @return TPLogger Logger instance.
  */
 public function getLogger($name)
 {
     if (!isset($this->loggers[$name])) {
         $logger = new TPLogger($name);
         $nodes = explode('.', $name);
         $firstNode = array_shift($nodes);
         // if name is not a first node but another first node is their
         if ($firstNode != $name and isset($this->loggers[$firstNode])) {
             $logger->setParent($this->loggers[$firstNode]);
         } else {
             // if there is no father, set root logger as father
             $logger->setParent($this->root);
         }
         // if there are more nodes than one
         if (count($nodes) > 0) {
             // find parent node
             foreach ($nodes as $node) {
                 $parentNode = "{$firstNode}.{$node}";
                 if (isset($this->loggers[$parentNode]) and $parentNode != $name) {
                     $logger->setParent($this->loggers[$parentNode]);
                 }
                 $firstNode .= ".{$node}";
             }
         }
         $this->loggers[$name] = $logger;
     }
     return $this->loggers[$name];
 }
 /**
  * Configures a logger. 
  * 
  * @param TPLogger $logger The logger to configure
  * @param array $config TPLogger configuration options.
  */
 private function configureLogger(TPLogger $logger, $config)
 {
     $loggerName = $logger->getName();
     // Set logger level
     if (isset($config['level'])) {
         $level = LoggerLevel::toLevel($config['level']);
         if (isset($level)) {
             $logger->setLevel($level);
         } else {
             $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'])) {
         try {
             $additivity = LoggerOptionConverter::toBooleanEx($config['additivity'], null);
             $logger->setAdditivity($additivity);
         } catch (Exception $ex) {
             $this->warn("Invalid additivity value [{$config['additivity']}] specified for logger [{$loggerName}]. Ignoring additivity setting.");
         }
     }
 }