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

logger filter in composite logger not combined properly

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 2.11.0
    • None
    • None

    Description

      When using a composite logger with DefaultMergeStrategy, logger filters aren't combined properly.

      Specifically, if the 'parent' configuration for the logger has no filter and the child configuration does, all attributes and children of the child filter are dropped from the composite configuration.

      For example, if my parent logger has:

          <Loggers>
              <Logger name="cat1" level="debug" additivity="false">
                  <AppenderRef ref="File"/>
              </Logger>
      

      and the child logger has:

          <Loggers>
              <Logger name="cat1" level="debug" additivity="false">
                  <RegexFilter regex=".*TEST.*" onMatch="DENY" onMismatch="ACCEPT" />
                  <AppenderRef ref="File"/>
              </Logger>
      

      DefaultMergeStrategy creates a RegexFilter node in the composite configuration with no attributes. You end up getting a message like this when the RegexFilter is constructed:

      2017-11-21 12:02:26,733 main ERROR A regular expression must be provided for RegexFilter
      

      Here: https://github.com/apache/logging-log4j2/blob/master/log4j-core/src/main/java/org/apache/logging/log4j/core/config/composite/DefaultMergeStrategy.java#L172-L174

      A new copy of the filter node is created, but the children and attributes aren't added to the new nodes.

      If the parent logger config does have a filter, it looks like it works correctly.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            jtolar Jacob Tolar
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment