private static function configureLog4php() { if (self::$configured == false) { self::$configured = true; self::$configurationFile = dirname(__FILE__) . DS . 'log4php-ideasa.properties'; $configutations = self::fillAllAppenders(); self::generateConfigFile($configutations); Ideasa_Log4php_Logger::configure(self::$configurationFile); } }
/** * @desc Returns string representation of throwable * * @return array */ public function getStringRepresentation() { if (!is_array($this->throwableArray)) { $renderer = Ideasa_Log4php_Logger::getHierarchy()->getRendererMap()->getByClassName(get_class($this->throwable)); // TODO: why this? if ($renderer instanceof Ideasa_Log4php_Renderers_LoggerRendererDefault) { $renderer = new Ideasa_Log4php_Renderers_LoggerRendererException(); } $this->throwableArray = explode("\n", $renderer->render($this->throwable)); } return $this->throwableArray; }
/** * This method must work for the root category as well. * * @param array $props array of properties * @param Ideasa_Log4php_Logger $logger * @param string $optionKey * @param string $loggerName * @param string $value * @return Ideasa_Log4php_Logger */ private function parseCategory($props, Ideasa_Log4php_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(Ideasa_Log4php_Helpers_LoggerOptionConverter::toLevel($levelStr, Ideasa_Log4php_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); } } }
/** * Initializes the log4php framework using the provided {@link * Logger::$configurationClass configuration class} and {@link * Logger::$configurationFile configuration file}. * @return boolean */ public static function initialize() { self::$initialized = true; $instance = Ideasa_Log4php_LoggerReflectionUtils::createObject(self::$configurationClass); $result = $instance->configure(self::getHierarchy(), self::$configurationFile); return $result; }
/** * 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 { // $this->logger might be null or an instance of Logger or RootLogger // But in contrast to log4j, in log4php there is only have one Ideasa_Log4php_LoggerHierarchy so there is // no need figure out which one is $this->logger part of. // TODO: Logger::getHierarchy() is marked @deprecated! $repository = Ideasa_Log4php_Logger::getHierarchy(); $rendererMap = $repository->getRendererMap(); $this->renderedMessage = $rendererMap->findAndRender($this->message); } } return $this->renderedMessage; }
/** * @param mixed $parser * @param string $tag * @param array $attribs * * @todo In 'LOGGER' case find a better way to detect 'getLogger()' method */ private function tagOpen($parser, $tag, $attribs) { switch ($tag) { case 'CONFIGURATION': case self::XMLNS . ':CONFIGURATION': if (isset($attribs['THRESHOLD'])) { $this->repository->setThreshold(Ideasa_Log4php_Helpers_LoggerOptionConverter::toLevel($this->subst($attribs['THRESHOLD']), $this->repository->getThreshold())); } break; case 'APPENDER': case self::XMLNS . ':APPENDER': unset($this->appender); $this->appender = null; $name = $this->subst(@$attribs['NAME']); $class = $this->subst(@$attribs['CLASS']); $this->appender = Ideasa_Log4php_LoggerAppenderPool::getAppenderFromPool($name, $class); if (isset($attribs['THRESHOLD'])) { $this->appender->setThreshold(Ideasa_Log4php_Helpers_LoggerOptionConverter::toLevel($this->subst($attribs['THRESHOLD']), $this->appender->getThreshold())); } $this->state[] = self::APPENDER_STATE; break; case 'APPENDER_REF': case 'APPENDER-REF': case self::XMLNS . ':APPENDER_REF': case self::XMLNS . ':APPENDER-REF': if (isset($attribs['REF']) and !empty($attribs['REF'])) { $appenderName = $this->subst($attribs['REF']); $appender = Ideasa_Log4php_LoggerAppenderPool::getAppenderFromPool($appenderName); if ($appender !== null) { switch (end($this->state)) { case self::LOGGER_STATE: case self::ROOT_STATE: $this->logger->addAppender($appender); break; } } } break; case 'FILTER': case self::XMLNS . ':FILTER': unset($this->filter); $this->filter = null; $filterName = basename($this->subst(@$attribs['CLASS'])); if (!empty($filterName)) { $this->filter = new $filterName(); $this->state[] = self::FILTER_STATE; } break; case 'LAYOUT': case self::XMLNS . ':LAYOUT': $class = @$attribs['CLASS']; $this->layout = Ideasa_Log4php_LoggerReflectionUtils::createObject($this->subst($class)); $this->state[] = self::LAYOUT_STATE; break; case 'LOGGER': case self::XMLNS . ':LOGGER': // $this->logger is assigned by reference. // Only '$this->logger=null;' destroys referenced object unset($this->logger); $this->logger = null; $loggerName = $this->subst(@$attribs['NAME']); if (!empty($loggerName)) { $this->logger = $this->repository->getLogger($loggerName); if ($this->logger !== null and isset($attribs['ADDITIVITY'])) { $additivity = Ideasa_Log4php_Helpers_LoggerOptionConverter::toBoolean($this->subst($attribs['ADDITIVITY']), true); $this->logger->setAdditivity($additivity); } } $this->state[] = self::LOGGER_STATE; break; case 'LEVEL': case self::XMLNS . ':LEVEL': case 'PRIORITY': case self::XMLNS . ':PRIORITY': if (!isset($attribs['VALUE'])) { // LoggerDOMConfigurator::tagOpen() LEVEL value not set break; } if ($this->logger === null) { // LoggerDOMConfigurator::tagOpen() LEVEL. parent logger is null break; } switch (end($this->state)) { case self::ROOT_STATE: $this->logger->setLevel(Ideasa_Log4php_Helpers_LoggerOptionConverter::toLevel($this->subst($attribs['VALUE']), $this->logger->getLevel())); break; case self::LOGGER_STATE: $this->logger->setLevel(Ideasa_Log4php_Helpers_LoggerOptionConverter::toLevel($this->subst($attribs['VALUE']), $this->logger->getLevel())); break; default: //LoggerLog::warn("LoggerDOMConfigurator::tagOpen() LEVEL state '{$this->state}' not allowed here"); } break; case 'PARAM': case self::XMLNS . ':PARAM': if (!isset($attribs['NAME'])) { // LoggerDOMConfigurator::tagOpen() PARAM attribute 'name' not defined. break; } if (!isset($attribs['VALUE'])) { // LoggerDOMConfigurator::tagOpen() PARAM. attribute 'value' not defined. break; } switch (end($this->state)) { case self::APPENDER_STATE: if ($this->appender !== null) { Ideasa_Log4php_LoggerReflectionUtils::setter($this->appender, $this->subst($attribs['NAME']), $this->subst($attribs['VALUE'])); } break; case self::LAYOUT_STATE: if ($this->layout !== null) { Ideasa_Log4php_LoggerReflectionUtils::setter($this->layout, $this->subst($attribs['NAME']), $this->subst($attribs['VALUE'])); } break; case self::FILTER_STATE: if ($this->filter !== null) { Ideasa_Log4php_LoggerReflectionUtils::setter($this->filter, $this->subst($attribs['NAME']), $this->subst($attribs['VALUE'])); } break; default: //LoggerLog::warn("LoggerDOMConfigurator::tagOpen() PARAM state '{$this->state}' not allowed here"); } break; case 'RENDERER': case self::XMLNS . ':RENDERER': $renderedClass = $this->subst(@$attribs['RENDEREDCLASS']); $renderingClass = $this->subst(@$attribs['RENDERINGCLASS']); if (!empty($renderedClass) and !empty($renderingClass)) { $this->repository->getRendererMap()->addRenderer($renderedClass, $renderingClass); } break; case 'ROOT': case self::XMLNS . ':ROOT': $this->logger = Ideasa_Log4php_Logger::getRootLogger(); $this->state[] = self::ROOT_STATE; break; } }
/** * Setting a null value to the level of the root category may have catastrophic results. * @param Ideasa_Log4php_LoggerLevel $level */ public function setLevel($level) { if ($level != null) { parent::setLevel($level); } }