/** * Return the decision of this filter. * * @param Payone_Log4php_LoggerLoggingEvent $event * @return integer */ public function decide(Payone_Log4php_LoggerLoggingEvent $event) { $level = $event->getLevel(); if ($this->levelMin !== null) { if ($level->isGreaterOrEqual($this->levelMin) == false) { // level of event is less than minimum return Payone_Log4php_LoggerFilter::DENY; } } if ($this->levelMax !== null) { if ($level->toInt() > $this->levelMax->toInt()) { // level of event is greater than maximum // Alas, there is no Level.isGreater method. and using // a combo of isGreaterOrEqual && !Equal seems worse than // checking the int values of the level objects.. return Payone_Log4php_LoggerFilter::DENY; } } if ($this->acceptOnMatch) { // this filter set up to bypass later filters and always return // accept if level in range return Payone_Log4php_LoggerFilter::ACCEPT; } else { // event is ok for this filter; allow later filters to have a look.. return Payone_Log4php_LoggerFilter::NEUTRAL; } }
/** * Constructor * * @param integer $level initial log level */ public function __construct($level = null) { parent::__construct('root'); if ($level == null) { $level = Payone_Log4php_LoggerLevel::getLevelAll(); } $this->setLevel($level); }
/** * Return the decision of this filter. * * Returns {@link LoggerFilter::NEUTRAL} if the <b><var>LevelToMatch</var></b> * option is not set or if there is not match. Otherwise, if there is a * match, then the returned decision is {@link LoggerFilter::ACCEPT} if the * <b><var>AcceptOnMatch</var></b> property is set to <i>true</i>. The * returned decision is {@link LoggerFilter::DENY} if the * <b><var>AcceptOnMatch</var></b> property is set to <i>false</i>. * * @param Payone_Log4php_LoggerLoggingEvent $event * @return integer */ public function decide(Payone_Log4php_LoggerLoggingEvent $event) { if ($this->levelToMatch === null) { return Payone_Log4php_LoggerFilter::NEUTRAL; } if ($this->levelToMatch->equals($event->getLevel())) { return $this->acceptOnMatch ? Payone_Log4php_LoggerFilter::ACCEPT : Payone_Log4php_LoggerFilter::DENY; } else { return Payone_Log4php_LoggerFilter::NEUTRAL; } }
public function append(Payone_Log4php_LoggerLoggingEvent $event) { if ($this->layout !== null) { $level = $event->getLevel(); if ($level->isGreaterOrEqual(Payone_Log4php_LoggerLevel::getLevelError())) { trigger_error($this->layout->format($event), E_USER_ERROR); } else { if ($level->isGreaterOrEqual(Payone_Log4php_LoggerLevel::getLevelWarn())) { trigger_error($this->layout->format($event), E_USER_WARNING); } else { trigger_error($this->layout->format($event), E_USER_NOTICE); } } } }
/** * Build a config that the Log4php_Logger accepts * @return array */ protected function buildInternalConfig() { $fileName = $this->getConfigValue('filename'); $fileSize = $this->getConfigValue('max_file_size'); $fileCount = $this->getConfigValue('max_file_count'); $internalConfig = array('appenders' => array(self::LOGGER_APPENDER_NAME => array('name' => self::LOGGER_APPENDER_NAME, 'class' => 'Payone_Log4php_LoggerAppenderRollingFile', 'layout' => array('class' => 'Payone_Log4php_LoggerLayoutTTCC'), 'params' => array('file' => $fileName, 'append' => TRUE, 'maxFileSize' => $fileSize, 'maxBackupIndex' => $fileCount))), 'rootLogger' => array('level' => Payone_Log4php_LoggerLevel::getLevelAll(), 'appenders' => array(self::LOGGER_APPENDER_NAME))); return $internalConfig; }
/** * 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."); } } }
/** * Check whether this Logger is enabled for the FATAL Level. * @return boolean */ public function isFatalEnabled() { return $this->isEnabledFor(Payone_Log4php_LoggerLevel::getLevelFatal()); }
/** * @param Payone_Log4php_LoggerLoggingEvent $event * @return string */ public function format(Payone_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(Payone_Log4php_LoggerLevel::getLevelDebug())) { $sbuf .= "<font color=\"#339933\">{$level}</font>"; } else { if ($level->equals(Payone_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; }
/** * Checks whether the message level is below the appender's threshold. * * If there is no threshold set, then the return value is always <i>true</i>. * * @param Payone_Log4php_LoggerLevel $level * @return boolean Returns true if level is greater or equal than * threshold, or if the threshold is not set. Otherwise returns false. */ public function isAsSevereAsThreshold($level) { if ($this->threshold === null) { return true; } return $level->isGreaterOrEqual($this->getThreshold()); }
/** * Reset all values contained in this hierarchy instance to their * default. * * This removes all appenders from all loggers, sets * the level of all non-root loggers 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}. * * <p>Existing loggers 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(Payone_Log4php_LoggerLevel::getLevelDebug()); $this->setThreshold(Payone_Log4php_LoggerLevel::getLevelAll()); $this->shutDown(); foreach ($this->loggers as $logger) { $logger->setLevel(null); $logger->setAdditivity(true); $logger->removeAllAppenders(); } $this->rendererMap->clear(); Payone_Log4php_LoggerAppenderPool::clear(); }
/** Converts the value to a level. Throws an exception if not possible. */ public static function toLevelEx($value) { if ($value instanceof Payone_Log4php_LoggerLevel) { return $value; } $level = Payone_Log4php_LoggerLevel::toLevel($value); if ($level === null) { throw new Payone_Log4php_LoggerException("Given value [" . var_export($value, true) . "] cannot be converted to a logger level."); } return $level; }
/** Determines which syslog priority to use based on the given level. */ private function getSyslogPriority(Payone_Log4php_LoggerLevel $level) { if ($this->overridePriority) { return $this->intPriority; } return $level->getSyslogEquivalent(); }