/** * Gets the internal Log4php_Logger, configured * @return Payone_Log4php_Logger */ public function getLogger() { if ($this->logger === null) { $this->logger = $this->buildLoggerDefault(); } $internalConfig = $this->buildInternalConfig(); $this->logger->configure($internalConfig); return $this->logger; }
/** * @desc Returns string representation of throwable * * @return array */ public function getStringRepresentation() { if (!is_array($this->throwableArray)) { $renderer = Payone_Log4php_Logger::getHierarchy()->getRendererMap()->getByClassName(get_class($this->throwable)); // TODO: why this? if ($renderer instanceof Payone_Log4php_LoggerRendererDefault) { $renderer = new Payone_Log4php_LoggerRendererException(); } $this->throwableArray = explode("\n", $renderer->render($this->throwable)); } return $this->throwableArray; }
/** * Configures a logger. * * @param Logger $logger The logger to configure * @param array $config Logger configuration options. */ private function configureLogger(Payone_Log4php_Logger $logger, $config) { $loggerName = $logger->getName(); // Set logger level if (isset($config['level'])) { $level = Payone_Log4php_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 = Payone_Log4php_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."); } } }
/** * 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; }
/** * Render message. * @return string */ public function getRenderedMessage() { if ($this->renderedMessage === null and $this->message !== null) { if (is_string($this->message)) { $this->renderedMessage = $this->message; } else { $rendererMap = Payone_Log4php_Logger::getHierarchy()->getRendererMap(); $this->renderedMessage = $rendererMap->findAndRender($this->message); } } return $this->renderedMessage; }
/** * Returns a named logger instance logger. If it doesn't exist, one is created. * * @param string $name Logger name * @return Logger Logger instance. */ public function getLogger($name) { if (!isset($this->loggers[$name])) { $logger = new Payone_Log4php_Logger($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]; }
/** * Setting a null value to the level of the root category may have catastrophic results. * @param Payone_Log4php_LoggerLevel $level */ public function setLevel($level) { if ($level != null) { parent::setLevel($level); } }