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

Incorrect attribute name in PropertiesRewritePolicy example

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.1
    • 2.2
    • Documentation
    • None

    Description

      http://logging.apache.org/log4j/2.0/manual/appenders.html#RewriteAppender

      On the documentation site on the Appenders page, under the RewriteAppender heading, RewritePolicy section, PropertiesRewritePolicy subsection, there is the following example:

      <?xml version="1.0" encoding="UTF-8"?>
      <Configuration status="warn" name="MyApp" packages="">
        <Appenders>
          <Console name="STDOUT" target="SYSTEM_OUT">
            <PatternLayout pattern="%m%n"/>
          </Console>
          <Rewrite name="rewrite">
            <AppenderRef ref="STDOUT"/>
            <PropertiesRewritePolicy>
              <Property key="user">${sys:user.name}</Property>
              <Property key="env">${sys:environment}</Property>
            </PropertiesRewritePolicy>
          </Rewrite>
        </Appenders>
        <Loggers>
          <Root level="error">
            <AppenderRef ref="Rewrite"/>
          </Root>
        </Loggers>
      </Configuration>
      

      The Configuration -> Appenders -> Rewrite -> PropertiesRewritePolicy -> Property nodes in the example are using an attribute with the name key. When tested in log4j 2.1, this did not work. However, using the attribute name did work.

      From the Documentation

            <PropertiesRewritePolicy>
              <Property key="user">${sys:user.name}</Property>
              <Property key="env">${sys:environment}</Property>
            </PropertiesRewritePolicy>
      

      Working Version

            <PropertiesRewritePolicy>
              <Property name="user">${sys:user.name}</Property>
              <Property name="env">${sys:environment}</Property>
            </PropertiesRewritePolicy>
      

      Attachments

        Activity

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

          People

            Unassigned Unassigned
            buzuli Joel Edwards
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment