Class ExpressionFilter

  • All Implemented Interfaces:
    org.apache.log4j.spi.OptionHandler

    public class ExpressionFilter
    extends org.apache.log4j.spi.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 org.apache.log4j.chainsaw.rule 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 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 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.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) boolean acceptOnMatch
      accept on match.
      (package private) boolean convertInFixToPostFix
      Convert in-fix to post-fix.
      (package private) java.lang.String expression
      Expression.
      (package private) Rule expressionRule
      Evaluated rule.
      • Fields inherited from class org.apache.log4j.spi.Filter

        ACCEPT, DENY, NEUTRAL, next
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void activateOptions()
      int decide​(org.apache.log4j.spi.LoggingEvent event)
      Determines if event matches the filter.
      boolean getAcceptOnMatch()
      Gets whether filter accepts matching or non-matching events.
      boolean getConvertInFixToPostFix()
      Get in-fix to post-fix conversion setting.
      java.lang.String getExpression()
      Get expression.
      void setAcceptOnMatch​(boolean newValue)
      Set whether filter should accept events if they match the expression.
      void setConvertInFixToPostFix​(boolean newValue)
      Set convert in-fix to post-fix.
      void setExpression​(java.lang.String exp)
      Set exp.
      • Methods inherited from class org.apache.log4j.spi.Filter

        getNext, setNext
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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.
    • Constructor Detail

      • ExpressionFilter

        public ExpressionFilter()
    • Method Detail

      • activateOptions

        public void activateOptions()
        Specified by:
        activateOptions in interface org.apache.log4j.spi.OptionHandler
        Overrides:
        activateOptions in class org.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:
        decide in class org.apache.log4j.spi.Filter
        Parameters:
        event - logging event;
        Returns:
        Filter.NEUTRAL is there is no string match.