org.apache.log4j.varia
Class ExpressionFilter
java.lang.Object
|
+--org.apache.log4j.spi.Filter
|
+--org.apache.log4j.varia.ExpressionFilter
- All Implemented Interfaces:
- OptionHandler
- public class ExpressionFilter
- extends Filter
A filter supporting complex expressions - supports both infix and postfix expressions
(infix expressions must first be converted to postfix prior to processing).
See org.apache.log4j.chainsaw.LoggingEventFieldResolver.java
for the correct names for logging event fields used when building expressions.
See package for a list of available rules which can
be applied using the expression syntax.
See org.apache.log4j.chainsaw.RuleFactory
for the symbols used to
activate the corresponding rules.
NOTE: Grouping using parentheses is supported - all tokens must be separated by spaces, and
operands which contain spaces are not yet supported.
Example:
In order to build a filter that displays all messages with infomsg-45 or infomsg-44 in the message,
as well as all messages with a level of WARN or higher, build an expression using
the LikeRule (supports ORO-based regular expressions) and the InequalityRule.
( MSG LIKE infomsg-4[4,5] ) && ( LEVEL >= WARN )
Three options are required:
Expression - the expression to match
ConvertInFixToPostFix - convert from infix to posfix (default true)
AcceptOnMatch - true or false (default true)
Meaning of AcceptToMatch:
If there is a match between the value of the
Expression option and the LoggingEvent
and AcceptOnMatch is true,
the decide(org.apache.log4j.spi.LoggingEvent)
method returns Filter.ACCEPT
.
If there is a match between the value of the
Expression option and the LoggingEvent
and AcceptOnMatch is false,
Filter.DENY
is returned.
If there is no match, Filter.NEUTRAL
is returned.
- Author:
- Scott Deboy sdeboy@apache.org
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ExpressionFilter
public ExpressionFilter()
activateOptions
public void activateOptions()
- Description copied from class:
Filter
- Usually filters options become active when set. We provide a
default do-nothing implementation for convenience.
- Specified by:
activateOptions
in interface OptionHandler
- Overrides:
activateOptions
in class Filter
setExpression
public void setExpression(java.lang.String expression)
getExpression
public java.lang.String getExpression()
setConvertInFixToPostFix
public void setConvertInFixToPostFix(boolean convertInFixToPostFix)
getConvertInFixToPostFix
public boolean getConvertInFixToPostFix()
setAcceptOnMatch
public void setAcceptOnMatch(boolean acceptOnMatch)
getAcceptOnMatch
public boolean getAcceptOnMatch()
decide
public int decide(LoggingEvent event)
- Returns
Filter.NEUTRAL
is there is no string match.
- Specified by:
decide
in class Filter
- Parameters:
event
- The LoggingEvent to decide upon.
Copyright 2000-2003 Apache Software Foundation.