Class LookupFilter

  • All Implemented Interfaces:
    org.apache.logging.log4j.core.Filter, org.apache.logging.log4j.core.LifeCycle, org.apache.logging.log4j.core.LifeCycle2

    @Plugin(name="LookupFilter",
            category="Core",
            elementType="filter",
            printObject=true)
    public class LookupFilter
    extends org.apache.logging.log4j.core.filter.AbstractFilter
    Generic log4j2 Filter using log4j lookup variable interpolation to decide if the log event will be logged by the Appender or not.

    Example usage:

    
         <LookupFilter key="jndi:logging/contextName" value="cms" onMatch="ACCEPT"/>
     

    The key attribute can interpolate all log4j2 Lookup variables which current value will be matched against the value attribute.

    Note: the log4j2 LookupFilter replaces the now deprecated log4j1 JndiPropertyFilter.


    Note: As of log4j2 2.16+, jndi based lookups are now by default disabled! The most common usage thereof, for brXM, is specifically the lookup of the logging/contextName to filter log events for specific contexts, as seen in the above example. This specific jndi lookup is not a security vulnerability however, so to cater for log4j2 2.16+ with disabled jndi lookup, a custom (fixed) workaround has been implemented which only intercepts a filter key="jndi:logging/contextName" and then do the jndi lookup directly, not via log4j2.

    • Nested Class Summary

      • Nested classes/interfaces inherited from class org.apache.logging.log4j.core.filter.AbstractFilter

        org.apache.logging.log4j.core.filter.AbstractFilter.AbstractFilterBuilder<B extends org.apache.logging.log4j.core.filter.AbstractFilter.AbstractFilterBuilder<B>>
      • Nested classes/interfaces inherited from interface org.apache.logging.log4j.core.Filter

        org.apache.logging.log4j.core.Filter.Result
      • Nested classes/interfaces inherited from interface org.apache.logging.log4j.core.LifeCycle

        org.apache.logging.log4j.core.LifeCycle.State
    • Field Summary

      • Fields inherited from class org.apache.logging.log4j.core.filter.AbstractFilter

        onMatch, onMismatch
      • Fields inherited from class org.apache.logging.log4j.core.AbstractLifeCycle

        DEFAULT_STOP_TIMEOUT, DEFAULT_STOP_TIMEUNIT, LOGGER
      • Fields inherited from interface org.apache.logging.log4j.core.Filter

        ELEMENT_TYPE, EMPTY_ARRAY
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected LookupFilter​(String key, String value, org.apache.logging.log4j.core.Filter.Result onMatch, org.apache.logging.log4j.core.Filter.Result onMismatch)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static LookupFilter createFilter​(String key, String value, org.apache.logging.log4j.core.Filter.Result match, org.apache.logging.log4j.core.Filter.Result mismatch)  
      protected org.apache.logging.log4j.core.Filter.Result filter()  
      org.apache.logging.log4j.core.Filter.Result filter​(org.apache.logging.log4j.core.LogEvent event)  
      org.apache.logging.log4j.core.Filter.Result filter​(org.apache.logging.log4j.core.Logger logger, org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, Object msg, Throwable t)  
      org.apache.logging.log4j.core.Filter.Result filter​(org.apache.logging.log4j.core.Logger logger, org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, String msg, Object... params)  
      org.apache.logging.log4j.core.Filter.Result filter​(org.apache.logging.log4j.core.Logger logger, org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, org.apache.logging.log4j.message.Message msg, Throwable t)  
      • Methods inherited from class org.apache.logging.log4j.core.filter.AbstractFilter

        equalsImpl, filter, filter, filter, filter, filter, filter, filter, filter, filter, filter, getOnMatch, getOnMismatch, hashCodeImpl, toString
      • Methods inherited from class org.apache.logging.log4j.core.AbstractLifeCycle

        getState, getStatusLogger, initialize, isInitialized, isStarted, isStarting, isStopped, isStopping, setStarted, setStarting, setState, setStopped, setStopping, start, stop, stop, stop
      • Methods inherited from interface org.apache.logging.log4j.core.LifeCycle

        getState, initialize, isStarted, isStopped, start, stop
    • Constructor Detail

      • LookupFilter

        protected LookupFilter​(String key,
                               String value,
                               org.apache.logging.log4j.core.Filter.Result onMatch,
                               org.apache.logging.log4j.core.Filter.Result onMismatch)
    • Method Detail

      • filter

        protected org.apache.logging.log4j.core.Filter.Result filter()
      • filter

        public org.apache.logging.log4j.core.Filter.Result filter​(org.apache.logging.log4j.core.LogEvent event)
        Specified by:
        filter in interface org.apache.logging.log4j.core.Filter
        Overrides:
        filter in class org.apache.logging.log4j.core.filter.AbstractFilter
      • filter

        public org.apache.logging.log4j.core.Filter.Result filter​(org.apache.logging.log4j.core.Logger logger,
                                                                  org.apache.logging.log4j.Level level,
                                                                  org.apache.logging.log4j.Marker marker,
                                                                  org.apache.logging.log4j.message.Message msg,
                                                                  Throwable t)
        Specified by:
        filter in interface org.apache.logging.log4j.core.Filter
        Overrides:
        filter in class org.apache.logging.log4j.core.filter.AbstractFilter
      • filter

        public org.apache.logging.log4j.core.Filter.Result filter​(org.apache.logging.log4j.core.Logger logger,
                                                                  org.apache.logging.log4j.Level level,
                                                                  org.apache.logging.log4j.Marker marker,
                                                                  Object msg,
                                                                  Throwable t)
        Specified by:
        filter in interface org.apache.logging.log4j.core.Filter
        Overrides:
        filter in class org.apache.logging.log4j.core.filter.AbstractFilter
      • filter

        public org.apache.logging.log4j.core.Filter.Result filter​(org.apache.logging.log4j.core.Logger logger,
                                                                  org.apache.logging.log4j.Level level,
                                                                  org.apache.logging.log4j.Marker marker,
                                                                  String msg,
                                                                  Object... params)
        Specified by:
        filter in interface org.apache.logging.log4j.core.Filter
        Overrides:
        filter in class org.apache.logging.log4j.core.filter.AbstractFilter
      • createFilter

        @PluginFactory
        public static LookupFilter createFilter​(@PluginAttribute("key")
                                                String key,
                                                @PluginAttribute("value")
                                                String value,
                                                @PluginAttribute("onMatch")
                                                org.apache.logging.log4j.core.Filter.Result match,
                                                @PluginAttribute("onMismatch")
                                                org.apache.logging.log4j.core.Filter.Result mismatch)