Package org.apache.log4j.rule
Class ExpressionRule
- java.lang.Object
-
- org.apache.log4j.rule.AbstractRule
-
- org.apache.log4j.rule.ExpressionRule
-
- All Implemented Interfaces:
java.io.Serializable
,Rule
public class ExpressionRule extends AbstractRule
A Rule class supporting both infix and postfix expressions, accepting any rule which is supported by theRuleFactory
. NOTE: parsing is supported through the use ofStringTokenizer
, which implies two limitations: 1: all tokens in the expression must be separated by spaces, including parenthesis 2: operands which contain spaces MUST be wrapped in single quotes. For example, the expression: msg == 'some msg' is a valid expression. 3: To group expressions, use parentheses. For example, the expression: level >= INFO || ( msg == 'some msg' || logger == 'test' ) is a valid expression. See org.apache.log4j.rule.InFixToPostFix for a description of supported operators. See org.apache.log4j.spi.LoggingEventFieldResolver for field keywords.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
ExpressionRule.PostFixExpressionCompiler
Evaluate a boolean postfix expression.
-
Field Summary
Fields Modifier and Type Field Description private static ExpressionRule.PostFixExpressionCompiler
COMPILER
Compiler.private static InFixToPostFix
CONVERTER
Converter.private Rule
rule
Rule.(package private) static long
serialVersionUID
Serialization ID.
-
Constructor Summary
Constructors Modifier Constructor Description private
ExpressionRule(Rule r)
Create new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
evaluate(org.apache.log4j.spi.LoggingEvent event, java.util.Map matches)
Returns true if this implementation of the rule accepts the LoggingEvent, or false if not.static Rule
getRule(java.lang.String expression)
Get rule.static Rule
getRule(java.lang.String expression, boolean isPostFix)
Get rule.java.lang.String
toString()
-
Methods inherited from class org.apache.log4j.rule.AbstractRule
addPropertyChangeListener, firePropertyChange, firePropertyChange, removePropertyChangeListener
-
-
-
-
Field Detail
-
serialVersionUID
static final long serialVersionUID
Serialization ID.- See Also:
- Constant Field Values
-
CONVERTER
private static final InFixToPostFix CONVERTER
Converter.
-
COMPILER
private static final ExpressionRule.PostFixExpressionCompiler COMPILER
Compiler.
-
rule
private final Rule rule
Rule.
-
-
Constructor Detail
-
ExpressionRule
private ExpressionRule(Rule r)
Create new instance.- Parameters:
r
- rule
-
-
Method Detail
-
getRule
public static Rule getRule(java.lang.String expression)
Get rule.- Parameters:
expression
- expression.- Returns:
- rule.
-
getRule
public static Rule getRule(java.lang.String expression, boolean isPostFix)
Get rule.- Parameters:
expression
- expression.isPostFix
- If post-fix.- Returns:
- rule
-
evaluate
public boolean evaluate(org.apache.log4j.spi.LoggingEvent event, java.util.Map matches)
Returns true if this implementation of the rule accepts the LoggingEvent, or false if not.What True/False means can be client-specific.
- Parameters:
event
- LoggingEvent this instance will evaluatematches
- a Map of event field keys to Sets of matching strings (may be null) which will be updated during execution of this method to include field and string matches based on the rule evaluation results- Returns:
- true if this Rule instance accepts the event, otherwise false.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-