Class LoggerFilterLevelRange

Description

This is a very simple filter based on level matching, which can be used to reject messages with priorities outside a certain range.

The filter admits three options <var>LevelMin</var>, <var>LevelMax</var> and <var>AcceptOnMatch</var>.

If the level of the LoggerLoggingEvent is not between Min and Max (inclusive), then LoggerFilter::DENY is returned.

If the Logging event level is within the specified range, then if <var>AcceptOnMatch</var> is true, LoggerFilter::ACCEPT is returned, and if <var>AcceptOnMatch</var> is false, LoggerFilter::NEUTRAL is returned.

If <var>LevelMin</var> is not defined, then there is no minimum acceptable level (i.e. a level is never rejected for being too "low"/unimportant). If <var>LevelMax</var> is not defined, then there is no maximum acceptable level (ie a level is never rejected for being too "high"/important).

Refer to the LoggerAppender::setThreshold() method available to all appenders extending LoggerAppender for a more convenient way to filter out events by level.

An example for this filter:

  1. require_once dirname(__FILE__).'/../../main/php/Logger.php';
  2.  
  3. Logger::configure(dirname(__FILE__).'/../resources/filter_levelrange.xml');
  4. $logger Logger::getRootLogger();
  5. $logger->debug("This is a debug message");
  6. $logger->info("This is an info message");
  7. $logger->warn("This is a warning");
  8. $logger->error("This is an error");
  9. $logger->fatal("This is a fatal error");

The corresponding XML file:

  1. <log4php:configuration
  2.   xmlns:log4php="http://logging.apache.org/log4php/"
  3.   threshold="all" debug="false">
  4.     <appender name="default" class="LoggerAppenderEcho">
  5.         <layout class="LoggerLayoutTTCC"/>
  6.         <filter class="LoggerFilterLevelRange">
  7.             <param name="LevelMin" value="ERROR" />
  8.                         <param name="LevelMax" value="FATAL" />
  9.             <param name="AcceptOnMatch" value="false" />
  10.         </filter>
  11.     </appender>
  12.     <root>
  13.         <level value="DEBUG" />
  14.         <appender_ref ref="default" />
  15.     </root>
  16. </log4php:configuration>

  • author: based on the org.apache.log4j.varia.LevelRangeFilte Java code by Ceki G&uuml;lc&uuml;
  • author: Simon Kitching
  • version: $Revision: 883108 $
  • since: 0.6

Located in /filters/LoggerFilterLevelRange.php (line 65)

LoggerFilter
   |
   --LoggerFilterLevelRange
Method Summary
integer decide (LoggerLoggingEvent $event)
void setAcceptOnMatch (boolean $acceptOnMatch)
void setLevelMax (string $l)
void setLevelMin (string $l)
Variables

Inherited Variables

Inherited from LoggerFilter

LoggerFilter::$next
Methods
decide (line 117)

Return the decision of this filter.

  • access: public
integer decide (LoggerLoggingEvent $event)

Redefinition of:
LoggerFilter::decide()
Decide what to do.
setAcceptOnMatch (line 85)
  • access: public
void setAcceptOnMatch (boolean $acceptOnMatch)
  • boolean $acceptOnMatch
setLevelMax (line 103)
  • access: public
void setLevelMax (string $l)
  • string $l: the level max to match
setLevelMin (line 92)
  • access: public
void setLevelMin (string $l)
  • string $l: the level min to match

Inherited Methods

Inherited From LoggerFilter

LoggerFilter::activateOptions()
LoggerFilter::addNext()
LoggerFilter::decide()
LoggerFilter::getNext()
Class Constants

Documentation generated on Fri, 27 Nov 2009 07:44:49 +0100 by phpDocumentor 1.4.3