Exemplo n.º 1
0
 /**
  * Initialize objects for logging. We have two logs files:
  * - gid-last-request.log: to see logger for the last request
  * - gid-all-requests.log: to see all logger for all request
  *
  * @param \LoggerHierarchy Object to handle objects for logging.
  * @param mixed Either path to the config file or the configuration as
  *     an array.
  * @return void
  */
 public function configure(\LoggerHierarchy $hierarchy, $input = null)
 {
     //Create a logger layout
     $layout = new \LoggerLayoutPattern();
     $layout->setConversionPattern("%d{Y-m-d H:i:s}[%r] %-5level %C.%M[%L] %msg%n");
     $layout->activateOptions();
     // Create an appender which logs to file
     $appLog = new \LoggerAppenderRollingFile('main');
     $appLog->setFile($this->log_path . 'gid-all-requests.log');
     $appLog->setAppend(true);
     $appLog->setMaxFileSize('2MB');
     $appLog->setMaxBackupIndex(5);
     $appLog->setThreshold($this->threshold);
     $appLog->setLayout($layout);
     $appLog->activateOptions();
     //Create an appender which logs Console
     $appConsole = new \LoggerAppenderFile('console');
     $appConsole->setFile($this->log_path . 'gid-last-request.log');
     $appConsole->setAppend(false);
     $appConsole->setThreshold($this->threshold);
     $appConsole->setLayout($layout);
     $appConsole->activateOptions();
     // Add appenders to the root logger
     $root = $hierarchy->getRootLogger();
     $root->addAppender($appLog);
     $root->addAppender($appConsole);
 }
 /**
  * Add a {@link LoggerAppenderConsole} that uses 
  * the {@link LoggerLayoutTTCC} to the root category.
  * 
  * @param string $url not used here
  */
 public function configure(LoggerHierarchy $hierarchy, $url = null)
 {
     $root = $hierarchy->getRootLogger();
     $appender = new LoggerAppenderConsole('A1');
     $appender->setLayout(new LoggerLayoutTTCC());
     $appender->activateOptions();
     $root->addAppender($appender);
 }
 public function testGetRootLoggerExisted()
 {
     $logger = new Logger('root');
     $hierarchy = new LoggerHierarchy();
     $hierarchy->setRootLogger($logger);
     $this->assertTrue($logger === $hierarchy->getRootLogger());
     $this->assertEquals(array(), $hierarchy->getAppenderMap());
 }
Exemplo n.º 4
0
 /**
  * @param array $props array of properties
  * @param LoggerHierarchy $hierarchy
  */
 private function configureRootCategory($props, LoggerHierarchy $hierarchy)
 {
     $effectivePrefix = self::ROOT_LOGGER_PREFIX;
     $value = @$props[self::ROOT_LOGGER_PREFIX];
     if (empty($value)) {
         $value = @$props[self::ROOT_CATEGORY_PREFIX];
         $effectivePrefix = self::ROOT_CATEGORY_PREFIX;
     }
     if (empty($value)) {
         // TODO "Could not find root logger information. Is this OK?"
     } else {
         $root = $hierarchy->getRootLogger();
         $this->parseCategory($props, $root, $effectivePrefix, self::INTERNAL_ROOT_NAME, $value);
     }
 }
 /** 
  * Configures the root logger
  * @see configureLogger() 
  */
 private function configureRootLogger(LoggerHierarchy $hierarchy, $config)
 {
     $logger = $hierarchy->getRootLogger();
     $this->configureLogger($logger, $config);
 }
 private function doConfigure($url, LoggerHierarchy $hierarchy)
 {
     $config = (require $url);
     // set threshold
     if (isset($config['threshold'])) {
         $hierarchy->setThreshold(LoggerOptionConverter::toLevel($config['threshold'], LoggerLevel::getLevelAll()));
     }
     // parse and create appenders
     if (isset($config['appenders'])) {
         foreach ($config['appenders'] as $appenderName => $appenderProperties) {
             $appender = LoggerAppenderPool::getAppenderFromPool($appenderName, $appenderProperties['class']);
             if ($appender->requiresLayout()) {
                 if (isset($appenderProperties['layout'])) {
                     if (isset($appenderProperties['layout']['class']) and !empty($appenderProperties['layout']['class'])) {
                         $layoutClass = $appenderProperties['layout']['class'];
                     } else {
                         $layoutClass = 'LoggerLayoutSimple';
                     }
                     $layout = LoggerReflectionUtils::createObject($layoutClass);
                     if ($layout === null) {
                         $layout = LoggerReflectionUtils::createObject('LoggerLayoutSimple');
                     }
                     if ($layout instanceof LoggerLayoutPattern) {
                         $layout->setConversionPattern($appenderProperties['layout']['conversionPattern']);
                     }
                     $appender->setLayout($layout);
                 } else {
                     // TODO: throw exception?
                 }
             }
         }
     }
     // parse and create root logger
     if (isset($config['rootLogger'])) {
         $rootLogger = $hierarchy->getRootLogger();
         if (isset($config['rootLogger']['level'])) {
             $rootLogger->setLevel(LoggerOptionConverter::toLevel($config['rootLogger']['level'], LoggerLevel::getLevelDebug()));
             if (isset($config['rootLogger']['appenders'])) {
                 foreach ($config['rootLogger']['appenders'] as $appenderName) {
                     $appender = LoggerAppenderPool::getAppenderFromPool($appenderName);
                     if ($appender !== null) {
                         $rootLogger->addAppender($appender);
                     }
                 }
             }
         }
     }
     // parse and create loggers
     if (isset($config['loggers'])) {
         foreach ($config['loggers'] as $loggerName => $loggerProperties) {
             if (is_string($loggerName)) {
                 $logger = $hierarchy->getLogger($loggerName);
                 if (isset($loggerProperties['level'])) {
                     $logger->setLevel(LoggerOptionConverter::toLevel($loggerProperties['level'], LoggerLevel::getLevelDebug()));
                     if (isset($loggerProperties['appenders'])) {
                         foreach ($loggerProperties['appenders'] as $appenderName) {
                             $appender = LoggerAppenderPool::getAppenderFromPool($appenderName);
                             if ($appender !== null) {
                                 $logger->addAppender($appender);
                             }
                         }
                     }
                 }
             } else {
                 // TODO: throw exception
             }
         }
     }
     return true;
 }
Exemplo n.º 7
0
 private function doConfigure($url, LoggerHierarchy $hierarchy)
 {
     if (!is_array($url)) {
         $config = (require $url);
     } else {
         $config = $url;
     }
     // set threshold
     if (isset($config['threshold'])) {
         $hierarchy->setThreshold(LoggerOptionConverter::toLevel($config['threshold'], LoggerLevel::getLevelAll()));
     }
     // add renderes
     if (isset($config['renderers'])) {
         foreach ($config['renderers'] as $renderedClass => $renderingClass) {
             $hierarchy->getRendererMap()->addRenderer($renderedClass, $renderingClass);
         }
     }
     // parse and create appenders
     if (isset($config['appenders'])) {
         foreach ($config['appenders'] as $appenderName => $appenderProperties) {
             $appender = LoggerAppenderPool::getAppenderFromPool($appenderName, $appenderProperties['class']);
             // unset so that the property wont be drawn up again
             unset($appenderProperties['class']);
             if ($appender->requiresLayout()) {
                 if (isset($appenderProperties['layout'])) {
                     if (isset($appenderProperties['layout']['class']) and !empty($appenderProperties['layout']['class'])) {
                         $layoutClass = $appenderProperties['layout']['class'];
                     } else {
                         $layoutClass = 'LoggerLayoutSimple';
                     }
                     $layout = LoggerReflectionUtils::createObject($layoutClass);
                     if ($layout === null) {
                         $layout = LoggerReflectionUtils::createObject('LoggerLayoutSimple');
                     }
                     if (isset($appenderProperties['file']) && method_exists($appender, 'setFileName')) {
                         $appender->setFile($appenderProperties['file'], true);
                     }
                     if ($layout instanceof LoggerLayoutPattern) {
                         $layout->setConversionPattern($appenderProperties['layout']['conversionPattern']);
                     }
                     $appender->setLayout($layout);
                     // unset so that the property wont be drawn up again
                     unset($appenderProperties['layout']);
                 } else {
                     // TODO: throw exception?
                 }
             }
             // set remaining properties and activate appender
             $setter = new LoggerReflectionUtils($appender);
             foreach ($appenderProperties as $key => $val) {
                 $setter->setProperty($key, $val);
             }
             $setter->activate();
         }
     }
     // parse and create root logger
     if (isset($config['rootLogger'])) {
         $rootLogger = $hierarchy->getRootLogger();
         if (isset($config['rootLogger']['level'])) {
             $rootLogger->setLevel(LoggerOptionConverter::toLevel($config['rootLogger']['level'], LoggerLevel::getLevelDebug()));
             if (isset($config['rootLogger']['appenders'])) {
                 foreach ($config['rootLogger']['appenders'] as $appenderName) {
                     $appender = LoggerAppenderPool::getAppenderFromPool($appenderName);
                     if ($appender !== null) {
                         $rootLogger->addAppender($appender);
                     }
                 }
             }
         }
     }
     // parse and create loggers
     if (isset($config['loggers'])) {
         foreach ($config['loggers'] as $loggerName => $loggerProperties) {
             if (is_string($loggerName)) {
                 $logger = $hierarchy->getLogger($loggerName);
                 if (isset($loggerProperties['level'])) {
                     $logger->setLevel(LoggerOptionConverter::toLevel($loggerProperties['level'], LoggerLevel::getLevelDebug()));
                     if (isset($loggerProperties['appenders'])) {
                         foreach ($loggerProperties['appenders'] as $appenderName) {
                             $appender = LoggerAppenderPool::getAppenderFromPool($appenderName);
                             if ($appender !== null) {
                                 $logger->addAppender($appender);
                             }
                         }
                     }
                 }
             } else {
                 // TODO: throw exception
             }
         }
     }
     return true;
 }