Class ExpressionRule

java.lang.Object
org.apache.log4j.rule.AbstractRule
org.apache.log4j.rule.ExpressionRule
All Implemented Interfaces:
Serializable, Rule

public class ExpressionRule extends AbstractRule
A Rule class supporting both infix and postfix expressions, accepting any rule which is supported by the RuleFactory. NOTE: parsing is supported through the use of StringTokenizer, 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:
  • Field Details

  • Constructor Details

    • ExpressionRule

      private ExpressionRule(Rule r)
      Create new instance.
      Parameters:
      r - rule
  • Method Details

    • getRule

      public static Rule getRule(String expression)
      Get rule.
      Parameters:
      expression - expression.
      Returns:
      rule.
    • getRule

      public static Rule getRule(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, 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 evaluate
      matches - 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 String toString()
      Overrides:
      toString in class Object