/**
  * 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);
         }
     }
 }
 private function doConfigure($url, Ideasa_Log4php_LoggerHierarchy $hierarchy)
 {
     if (!is_array($url)) {
         $config = (require $url);
     } else {
         $config = $url;
     }
     // set threshold
     if (isset($config['threshold'])) {
         $hierarchy->setThreshold(Ideasa_Log4php_Helpers_LoggerOptionConverter::toLevel($config['threshold'], Ideasa_Log4php_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 = Ideasa_Log4php_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 = 'Ideasa_Log4php_Layouts_LoggerLayoutSimple';
                     }
                     $layout = Ideasa_Log4php_LoggerReflectionUtils::createObject($layoutClass);
                     if ($layout === null) {
                         $layout = Ideasa_Log4php_LoggerReflectionUtils::createObject('Ideasa_Log4php_Layouts_LoggerLayoutSimple');
                     }
                     if (isset($appenderProperties['file']) && method_exists($appender, 'setFileName')) {
                         $appender->setFile($appenderProperties['file'], true);
                     }
                     if ($layout instanceof Ideasa_Log4php_Layouts_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 Ideasa_Log4php_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(Ideasa_Log4php_Helpers_LoggerOptionConverter::toLevel($config['rootLogger']['level'], Ideasa_Log4php_LoggerLevel::getLevelDebug()));
             if (isset($config['rootLogger']['appenders'])) {
                 foreach ($config['rootLogger']['appenders'] as $appenderName) {
                     $appender = Ideasa_Log4php_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(Ideasa_Log4php_Helpers_LoggerOptionConverter::toLevel($loggerProperties['level'], Ideasa_Log4php_LoggerLevel::getLevelDebug()));
                     if (isset($loggerProperties['appenders'])) {
                         foreach ($loggerProperties['appenders'] as $appenderName) {
                             $appender = Ideasa_Log4php_LoggerAppenderPool::getAppenderFromPool($appenderName);
                             if ($appender !== null) {
                                 $logger->addAppender($appender);
                             }
                         }
                     }
                 }
             } else {
                 // TODO: throw exception
             }
         }
     }
     return true;
 }
Exemplo n.º 3
0
 /**
  * Check whether this Logger is enabled for the DEBUG Level.
  * @return boolean
  */
 public function isDebugEnabled()
 {
     return $this->isEnabledFor(Ideasa_Log4php_LoggerLevel::getLevelDebug());
 }
Exemplo n.º 4
0
 public function append(Ideasa_Log4php_LoggerLoggingEvent $event)
 {
     if ($this->_option == NULL) {
         $this->_option = LOG_PID | LOG_CONS;
     }
     $level = $event->getLevel();
     if ($this->layout === null) {
         $message = $event->getRenderedMessage();
     } else {
         $message = $this->layout->format($event);
     }
     // If the priority of a syslog message can be overridden by a value defined in the properties-file,
     // use that value, else use the one that is defined in the code.
     if (!$this->dry) {
         // Attach the process ID to the message, use the facility defined in the .properties-file
         openlog($this->_ident, $this->_option, $this->_facility);
         if ($this->_overridePriority) {
             syslog($this->_priority, $message);
         } else {
             if ($level->isGreaterOrEqual(Ideasa_Log4php_LoggerLevel::getLevelFatal())) {
                 syslog(LOG_ALERT, $message);
             } else {
                 if ($level->isGreaterOrEqual(Ideasa_Log4php_LoggerLevel::getLevelError())) {
                     syslog(LOG_ERR, $message);
                 } else {
                     if ($level->isGreaterOrEqual(Ideasa_Log4php_LoggerLevel::getLevelWarn())) {
                         syslog(LOG_WARNING, $message);
                     } else {
                         if ($level->isGreaterOrEqual(Ideasa_Log4php_LoggerLevel::getLevelInfo())) {
                             syslog(LOG_INFO, $message);
                         } else {
                             if ($level->isGreaterOrEqual(Ideasa_Log4php_LoggerLevel::getLevelDebug())) {
                                 syslog(LOG_DEBUG, $message);
                             } else {
                                 if ($level->isGreaterOrEqual(Ideasa_Log4php_LoggerLevel::getLevelTrace())) {
                                     syslog(LOG_DEBUG, $message);
                                     // No trace level in syslog
                                 }
                             }
                         }
                     }
                 }
             }
         }
         closelog();
     } else {
         echo "DRY MODE OF SYSLOG APPENDER: " . $message;
     }
 }
Exemplo n.º 5
0
 /**
  * Reset all values contained in this hierarchy instance to their
  * default. 
  *
  * This removes all appenders from all categories, sets
  * the level of all non-root categories to <i>null</i>,
  * sets their additivity flag to <i>true</i> and sets the level
  * of the root logger to {@link LOGGER_LEVEL_DEBUG}.  Moreover,
  * message disabling is set its default "off" value.
  * 
  * <p>Existing categories are not removed. They are just reset.
  *
  * <p>This method should be used sparingly and with care as it will
  * block all logging until it is completed.</p>
  */
 public function resetConfiguration()
 {
     $root = $this->getRootLogger();
     $root->setLevel(Ideasa_Log4php_LoggerLevel::getLevelDebug());
     $this->setThreshold(Ideasa_Log4php_LoggerLevel::getLevelAll());
     $this->shutDown();
     $loggers = $this->getCurrentLoggers();
     $enumLoggers = count($loggers);
     for ($i = 0; $i < $enumLoggers; $i++) {
         $loggers[$i]->setLevel(null);
         $loggers[$i]->setAdditivity(true);
         $loggers[$i]->removeAllAppenders();
     }
     $this->rendererMap->clear();
     Ideasa_Log4php_LoggerAppenderPool::clear();
 }
Exemplo n.º 6
0
 /**
  * @param Ideasa_Log4php_LoggerLoggingEvent $event
  * @return string
  */
 public function format(Ideasa_Log4php_LoggerLoggingEvent $event)
 {
     $sbuf = PHP_EOL . "<tr>" . PHP_EOL;
     $sbuf .= "<td>";
     $sbuf .= $event->getTime();
     $sbuf .= "</td>" . PHP_EOL;
     $sbuf .= "<td title=\"" . $event->getThreadName() . " thread\">";
     $sbuf .= $event->getThreadName();
     $sbuf .= "</td>" . PHP_EOL;
     $sbuf .= "<td title=\"Level\">";
     $level = $event->getLevel();
     if ($level->equals(Ideasa_Log4php_LoggerLevel::getLevelDebug())) {
         $sbuf .= "<font color=\"#339933\">{$level}</font>";
     } else {
         if ($level->equals(Ideasa_Log4php_LoggerLevel::getLevelWarn())) {
             $sbuf .= "<font color=\"#993300\"><strong>{$level}</strong></font>";
         } else {
             $sbuf .= $level;
         }
     }
     $sbuf .= "</td>" . PHP_EOL;
     $sbuf .= "<td title=\"" . htmlentities($event->getLoggerName(), ENT_QUOTES) . " category\">";
     $sbuf .= htmlentities($event->getLoggerName(), ENT_QUOTES);
     $sbuf .= "</td>" . PHP_EOL;
     if ($this->locationInfo) {
         $locInfo = $event->getLocationInformation();
         $sbuf .= "<td>";
         $sbuf .= htmlentities($locInfo->getFileName(), ENT_QUOTES) . ':' . $locInfo->getLineNumber();
         $sbuf .= "</td>" . PHP_EOL;
     }
     $sbuf .= "<td title=\"Message\">";
     $sbuf .= htmlentities($event->getRenderedMessage(), ENT_QUOTES);
     $sbuf .= "</td>" . PHP_EOL;
     $sbuf .= "</tr>" . PHP_EOL;
     if ($event->getNDC() != null) {
         $sbuf .= "<tr><td bgcolor=\"#EEEEEE\" style=\"font-size : xx-small;\" colspan=\"6\" title=\"Nested Diagnostic Context\">";
         $sbuf .= "NDC: " . htmlentities($event->getNDC(), ENT_QUOTES);
         $sbuf .= "</td></tr>" . PHP_EOL;
     }
     return $sbuf;
 }