Package org.apache.log4j.filter
Class ExpressionFilter
- java.lang.Object
-
- org.apache.log4j.spi.Filter
-
- org.apache.log4j.filter.ExpressionFilter
-
- All Implemented Interfaces:
org.apache.log4j.spi.OptionHandler
public class ExpressionFilter extends org.apache.log4j.spi.FilterA 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.javafor the correct names for logging event fields used when building expressions.See
org.apache.log4j.chainsaw.rulepackage for a list of available rules which can be applied using the expression syntax.See
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 java.util.regex 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 theorg.apache.log4j.chainsaw.RuleFactoryfor the symbols used to activate the corresponding rules.LoggingEventand AcceptOnMatch is true, thedecide(org.apache.log4j.spi.LoggingEvent)method returnsFilter.ACCEPT. If there is a match between the value of the Expression option and theLoggingEventand AcceptOnMatch is false,Filter.DENYis returned. If there is no match,Filter.NEUTRALis returned.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) booleanacceptOnMatchaccept on match.(package private) booleanconvertInFixToPostFixConvert in-fix to post-fix.(package private) java.lang.StringexpressionExpression.(package private) RuleexpressionRuleEvaluated rule.
-
Constructor Summary
Constructors Constructor Description ExpressionFilter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactivateOptions()intdecide(org.apache.log4j.spi.LoggingEvent event)Determines if event matches the filter.booleangetAcceptOnMatch()Gets whether filter accepts matching or non-matching events.booleangetConvertInFixToPostFix()Get in-fix to post-fix conversion setting.java.lang.StringgetExpression()Get expression.voidsetAcceptOnMatch(boolean newValue)Set whether filter should accept events if they match the expression.voidsetConvertInFixToPostFix(boolean newValue)Set convert in-fix to post-fix.voidsetExpression(java.lang.String exp)Set exp.
-
-
-
Field Detail
-
acceptOnMatch
boolean acceptOnMatch
accept on match.
-
convertInFixToPostFix
boolean convertInFixToPostFix
Convert in-fix to post-fix.
-
expression
java.lang.String expression
Expression.
-
expressionRule
Rule expressionRule
Evaluated rule.
-
-
Method Detail
-
activateOptions
public void activateOptions()
- Specified by:
activateOptionsin interfaceorg.apache.log4j.spi.OptionHandler- Overrides:
activateOptionsin classorg.apache.log4j.spi.Filter
-
setExpression
public void setExpression(java.lang.String exp)
Set exp.- Parameters:
exp- exp.
-
getExpression
public java.lang.String getExpression()
Get expression.- Returns:
- expression.
-
setConvertInFixToPostFix
public void setConvertInFixToPostFix(boolean newValue)
Set convert in-fix to post-fix.- Parameters:
newValue- new value.
-
getConvertInFixToPostFix
public boolean getConvertInFixToPostFix()
Get in-fix to post-fix conversion setting.- Returns:
- true if in-fix expressions are converted to post-fix.
-
setAcceptOnMatch
public void setAcceptOnMatch(boolean newValue)
Set whether filter should accept events if they match the expression.- Parameters:
newValue- if true, accept on match.
-
getAcceptOnMatch
public boolean getAcceptOnMatch()
Gets whether filter accepts matching or non-matching events.- Returns:
- if true, accept matching events.
-
decide
public int decide(org.apache.log4j.spi.LoggingEvent event)
Determines if event matches the filter.- Specified by:
decidein classorg.apache.log4j.spi.Filter- Parameters:
event- logging event;- Returns:
Filter.NEUTRALis there is no string match.
-
-