Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-2414

RegexFilter GC-Free way



    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.11.0
    • None
    • Filters
    • None


      We are now trying to tune log4j2 to work in GC-Free mode.

      One of the filters I'm trying to use is RegexFilter. Based on my observation it does produce garbage (when using with useRawMessage). Documentation (https://logging.apache.org/log4j/2.x/manual/garbagefree.html) states: 

      "Other filters like BurstFilter, RegexFilter and ScriptFilter are not trivial to make garbage free, and there is currently no plan to change them."

      However, I don't think it is difficult, in case if logging is done in single thread (is it the case of Disruptor?) and pattern is constant (which it is)

      so instead of doing:

      private Result filter(final String msg) {
          if (msg == null) {
              return onMismatch;
          final Matcher m = pattern.matcher(msg);
          return m.matches() ? onMatch : onMismatch;

      It worth adding matcher into constructor:

      matcher = pattern.matcher( "init_string" );

      and then something like:

          public Result filter(final LogEvent event) {
      //TODO: acomodate usage of useRawMessage
              if (event.getMessage().getFormat() == null) {
                  return onMismatch;
              matcher.reset( event.getMessage().getFormat() );
              return matcher.matches() ? onMatch : onMismatch;

      It looks like this approach will not work in case of concurrent access to filter. But in case of using Disruptor, there should be single processing thread anyway, that processes RingBufferEvents.

      Do you think it possible to somehow extend this filter, or create new one that can be used in case of log event processing after Disruptor?




            Unassigned Unassigned
            ebogdanov Evgeniy
            0 Vote for this issue
            1 Start watching this issue