/**
  * Add a renderer to a hierarchy passed as parameter.
  * Note that hierarchy must implement getRendererMap() and setRenderer() methods.
  *
  * @param LoggerHierarchy $repository a logger repository.
  * @param string $renderedClassName
  * @param string $renderingClassName
  * @static
  */
 public static function addRenderer($repository, $renderedClassName, $renderingClassName)
 {
     $renderer = LoggerReflectionUtils::createObject($renderingClassName);
     if ($renderer == null) {
         return;
     } else {
         $repository->setRenderer($renderedClassName, $renderer);
     }
 }
Exemplo n.º 2
0
 /**
  * Add a renderer to a hierarchy passed as parameter.
  * Note that hierarchy must implement getRendererMap() and setRenderer() methods.
  *
  * @param LoggerHierarchy $repository a logger repository.
  * @param string $renderedClassName
  * @param string $renderingClassName
  * @static
  */
 public static function addRenderer($repository, $renderedClassName, $renderingClassName)
 {
     LoggerLog::debug("LoggerRendererMap::addRenderer() Rendering class: [{$renderingClassName}], Rendered class: [{$renderedClassName}].");
     $renderer = LoggerObjectRenderer::factory($renderingClassName);
     if ($renderer == null) {
         LoggerLog::warn("LoggerRendererMap::addRenderer() Could not instantiate renderer [{$renderingClassName}].");
         return;
     } else {
         $repository->setRenderer($renderedClassName, $renderer);
     }
 }
 /**
  * @param mixed $parser
  * @param string $tag
  * @param array $attribs
  *
  * @todo In 'LOGGER' case find a better way to detect 'getLogger()' method
  */
 function tagOpen($parser, $tag, $attribs)
 {
     switch ($tag) {
         case 'CONFIGURATION':
         case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS . ':CONFIGURATION':
             LoggerLog::debug("LoggerDOMConfigurator::tagOpen() CONFIGURATION");
             if (isset($attribs['THRESHOLD'])) {
                 $this->repository->setThreshold(LoggerOptionConverter::toLevel($this->subst($attribs['THRESHOLD']), $this->repository->getThreshold()));
             }
             if (isset($attribs['DEBUG'])) {
                 $debug = LoggerOptionConverter::toBoolean($this->subst($attribs['DEBUG']), LoggerLog::internalDebugging());
                 $this->repository->debug = $debug;
                 LoggerLog::internalDebugging($debug);
                 LoggerLog::debug("LoggerDOMConfigurator::tagOpen() LOG4PHP:CONFIGURATION. Internal Debug turned " . ($debug ? 'on' : 'off'));
             }
             break;
         case 'APPENDER':
         case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS . ':APPENDER':
             unset($this->appender);
             $this->appender = null;
             $name = $this->subst(@$attribs['NAME']);
             $class = $this->subst(@$attribs['CLASS']);
             LoggerLog::debug("LoggerDOMConfigurator::tagOpen():tag=[{$tag}]:name=[{$name}]:class=[{$class}]");
             $this->appender =& LoggerAppender::singleton($name, $class);
             if ($this->appender === null) {
                 LoggerLog::warn("LoggerDOMConfigurator::tagOpen() APPENDER cannot instantiate appender '{$name}'");
             }
             $this->state[] = LOG4PHP_LOGGER_DOM_CONFIGURATOR_APPENDER_STATE;
             break;
         case 'APPENDER_REF':
         case 'APPENDER-REF':
         case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS . ':APPENDER_REF':
         case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS . ':APPENDER-REF':
             if (isset($attribs['REF']) and !empty($attribs['REF'])) {
                 $appenderName = $this->subst($attribs['REF']);
                 LoggerLog::debug("LoggerDOMConfigurator::tagOpen() APPENDER-REF ref='{$appenderName}'");
                 $appender =& LoggerAppender::singleton($appenderName);
                 if ($appender !== null) {
                     switch (end($this->state)) {
                         case LOG4PHP_LOGGER_DOM_CONFIGURATOR_LOGGER_STATE:
                         case LOG4PHP_LOGGER_DOM_CONFIGURATOR_ROOT_STATE:
                             $this->logger->addAppender($appender);
                             break;
                     }
                 } else {
                     LoggerLog::warn("LoggerDOMConfigurator::tagOpen() APPENDER-REF ref '{$appenderName}' points to a null appender");
                 }
             } else {
                 LoggerLog::warn("LoggerDOMConfigurator::tagOpen() APPENDER-REF ref not set or empty");
             }
             break;
         case 'FILTER':
         case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS . ':FILTER':
             LoggerLog::debug("LoggerDOMConfigurator::tagOpen() FILTER");
             unset($this->filter);
             $this->filter = null;
             $filterName = basename($this->subst(@$attribs['CLASS']));
             if (!empty($filterName)) {
                 if (!class_exists($filterName)) {
                     @(include_once LOG4PHP_DIR . "/varia/{$filterName}.php");
                 }
                 if (class_exists($filterName)) {
                     $this->filter = new $filterName();
                 } else {
                     LoggerLog::warn("LoggerDOMConfigurator::tagOpen() FILTER. class '{$filterName}' doesnt exist");
                 }
                 $this->state[] = LOG4PHP_LOGGER_DOM_CONFIGURATOR_FILTER_STATE;
             } else {
                 LoggerLog::warn("LoggerDOMConfigurator::tagOpen() FILTER filter name cannot be empty");
             }
             break;
         case 'LAYOUT':
         case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS . ':LAYOUT':
             $class = @$attribs['CLASS'];
             LoggerLog::debug("LoggerDOMConfigurator::tagOpen() LAYOUT class='{$class}'");
             $this->layout = LoggerLayout::factory($this->subst($class));
             if ($this->layout === null) {
                 LoggerLog::warn("LoggerDOMConfigurator::tagOpen() LAYOUT unable to instanciate class='{$class}'");
             }
             $this->state[] = LOG4PHP_LOGGER_DOM_CONFIGURATOR_LAYOUT_STATE;
             break;
         case 'LOGGER':
         case LOG4PHP_LOGGER_DOM_CONFIGURATOR_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)) {
                 LoggerLog::debug("LoggerDOMConfigurator::tagOpen() LOGGER. name='{$loggerName}'");
                 $class = $this->subst(@$attribs['CLASS']);
                 if (empty($class)) {
                     $this->logger =& $this->repository->getLogger($loggerName);
                 } else {
                     $className = basename($class);
                     if (!class_exists($className)) {
                         @(include_once "{$class}.php");
                     }
                     if (!class_exists($className)) {
                         LoggerLog::warn("LoggerDOMConfigurator::tagOpen() LOGGER. " . "cannot find '{$className}'.");
                     } else {
                         if (in_array('getlogger', get_class_methods($className))) {
                             $this->logger =& call_user_func(array($className, 'getlogger'), $loggerName);
                         } else {
                             LoggerLog::warn("LoggerDOMConfigurator::tagOpen() LOGGER. " . "class '{$className}' doesnt implement 'getLogger()' method.");
                         }
                     }
                 }
                 if ($this->logger !== null and isset($attribs['ADDITIVITY'])) {
                     $additivity = LoggerOptionConverter::toBoolean($this->subst($attribs['ADDITIVITY']), true);
                     $this->logger->setAdditivity($additivity);
                 }
             } else {
                 LoggerLog::warn("LoggerDOMConfigurator::tagOpen() LOGGER. Attribute 'name' is not set or is empty.");
             }
             $this->state[] = LOG4PHP_LOGGER_DOM_CONFIGURATOR_LOGGER_STATE;
             break;
         case 'LEVEL':
         case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS . ':LEVEL':
         case 'PRIORITY':
         case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS . ':PRIORITY':
             if (!isset($attribs['VALUE'])) {
                 LoggerLog::debug("LoggerDOMConfigurator::tagOpen() LEVEL value not set");
                 break;
             }
             LoggerLog::debug("LoggerDOMConfigurator::tagOpen() LEVEL value={$attribs['VALUE']}");
             if ($this->logger === null) {
                 LoggerLog::warn("LoggerDOMConfigurator::tagOpen() LEVEL. parent logger is null");
                 break;
             }
             switch (end($this->state)) {
                 case LOG4PHP_LOGGER_DOM_CONFIGURATOR_ROOT_STATE:
                     $this->logger->setLevel(LoggerOptionConverter::toLevel($this->subst($attribs['VALUE']), $this->logger->getLevel()));
                     LoggerLog::debug("LoggerDOMConfigurator::tagOpen() LEVEL root level is now '{$attribs['VALUE']}' ");
                     break;
                 case LOG4PHP_LOGGER_DOM_CONFIGURATOR_LOGGER_STATE:
                     $this->logger->setLevel(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 LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS . ':PARAM':
             LoggerLog::debug("LoggerDOMConfigurator::tagOpen() PARAM");
             if (!isset($attribs['NAME'])) {
                 LoggerLog::warn("LoggerDOMConfigurator::tagOpen() PARAM. " . "attribute 'name' not defined.");
                 break;
             }
             if (!isset($attribs['VALUE'])) {
                 LoggerLog::warn("LoggerDOMConfigurator::tagOpen() PARAM. " . "attribute 'value' not defined.");
                 break;
             }
             switch (end($this->state)) {
                 case LOG4PHP_LOGGER_DOM_CONFIGURATOR_APPENDER_STATE:
                     if ($this->appender !== null) {
                         $this->setter($this->appender, $this->subst($attribs['NAME']), $this->subst($attribs['VALUE']));
                     } else {
                         LoggerLog::warn("LoggerDOMConfigurator::tagOpen() PARAM. " . " trying to set property to a null appender.");
                     }
                     break;
                 case LOG4PHP_LOGGER_DOM_CONFIGURATOR_LAYOUT_STATE:
                     if ($this->layout !== null) {
                         $this->setter($this->layout, $this->subst($attribs['NAME']), $this->subst($attribs['VALUE']));
                     } else {
                         LoggerLog::warn("LoggerDOMConfigurator::tagOpen() PARAM. " . " trying to set property to a null layout.");
                     }
                     break;
                 case LOG4PHP_LOGGER_DOM_CONFIGURATOR_FILTER_STATE:
                     if ($this->filter !== null) {
                         $this->setter($this->filter, $this->subst($attribs['NAME']), $this->subst($attribs['VALUE']));
                     } else {
                         LoggerLog::warn("LoggerDOMConfigurator::tagOpen() PARAM. " . " trying to set property to a null filter.");
                     }
                     break;
                 default:
                     LoggerLog::warn("LoggerDOMConfigurator::tagOpen() PARAM state '{$this->state}' not allowed here");
             }
             break;
         case 'RENDERER':
         case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS . ':RENDERER':
             $renderedClass = $this->subst(@$attribs['RENDEREDCLASS']);
             $renderingClass = $this->subst(@$attribs['RENDERINGCLASS']);
             LoggerLog::debug("LoggerDOMConfigurator::tagOpen() RENDERER renderedClass='{$renderedClass}' renderingClass='{$renderingClass}'");
             if (!empty($renderedClass) and !empty($renderingClass)) {
                 $renderer = LoggerObjectRenderer::factory($renderingClass);
                 if ($renderer === null) {
                     LoggerLog::warn("LoggerDOMConfigurator::tagOpen() RENDERER cannot instantiate '{$renderingClass}'");
                 } else {
                     $this->repository->setRenderer($renderedClass, $renderer);
                 }
             } else {
                 LoggerLog::warn("LoggerDOMConfigurator::tagOpen() RENDERER renderedClass or renderingClass is empty");
             }
             break;
         case 'ROOT':
         case LOG4PHP_LOGGER_DOM_CONFIGURATOR_XMLNS . ':ROOT':
             LoggerLog::debug("LoggerDOMConfigurator::tagOpen() ROOT");
             $this->logger =& LoggerManager::getRootLogger();
             $this->state[] = LOG4PHP_LOGGER_DOM_CONFIGURATOR_ROOT_STATE;
             break;
     }
 }
 /**
  * @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(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 = LoggerAppenderPool::getAppenderFromPool($name, $class);
             $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 = 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 = 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 = 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(LoggerOptionConverter::toLevel($this->subst($attribs['VALUE']), $this->logger->getLevel()));
                     break;
                 case self::LOGGER_STATE:
                     $this->logger->setLevel(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) {
                         LoggerReflectionUtils::setter($this->appender, $this->subst($attribs['NAME']), $this->subst($attribs['VALUE']));
                     }
                     break;
                 case self::LAYOUT_STATE:
                     if ($this->layout !== null) {
                         LoggerReflectionUtils::setter($this->layout, $this->subst($attribs['NAME']), $this->subst($attribs['VALUE']));
                     }
                     break;
                 case self::FILTER_STATE:
                     if ($this->filter !== null) {
                         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)) {
                 $renderer = LoggerReflectionUtils::createObject($renderingClass);
                 if ($renderer === null) {
                     // LoggerDOMConfigurator::tagOpen() RENDERER cannot instantiate '$renderingClass'
                 } else {
                     $this->repository->setRenderer($renderedClass, $renderer);
                 }
             }
             break;
         case 'ROOT':
         case self::XMLNS . ':ROOT':
             $this->logger = Logger::getRootLogger();
             $this->state[] = self::ROOT_STATE;
             break;
     }
 }