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

Combining Root and AsyncRoot in Xml configuration

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 2.1
    • 2.4
    • None
    • None

    Description

      Don't know if this is a documentation issue, a configuration bug, or just a user error, so I have left many fields empty in this report.

      I'm trying to create an xml configuration where I have asynchronous logging to a socket, and synchronous logging to disk.

      The pdf-documentation says:
      http://logging.apache.org/log4j/2.x/log4j-users-guide.pdf

      "Synchronous and asynchronous loggers can be combined in configuration. This gives you more
      flexibility at the cost of a slight loss in performance (compared to making all loggers asynchronous).
      Use the <asyncRoot> or <asyncLogger> configuration elements to specify the loggers that need to
      be asynchronous. The same configuration file can also contain <root> and <logger> elements for
      the synchronous loggers."

      .. so I created a configuration file that looks like this:

      <?xml version="1.0" encoding="UTF-8"?>
      <Configuration status="trace">
      	<Appenders>
      		<Console name="Console" target="SYSTEM_OUT">
      			<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
      		</Console>
      		<Socket name="Socket" host="localhost" port="666" immediateFail="false" immediateFlush="true" reconnectionDelayMillis="5000">
      			<SerializedLayout />
       		</Socket>
      	</Appenders>
      	<Loggers>
      		<Root level="debug" includeLocation="false">
      			<AppenderRef ref="Console" />
      		</Root>
      		<AsyncRoot level="debug" includeLocation="false">
            		<AppenderRef ref="Socket"/>
      	    </AsyncRoot>	
      	</Loggers>
      </Configuration>
      

      That configuration only leads to logging to the socket appender, and nothing to the console.

      Changing the order of the root elements to:

      	<Loggers>
      		<AsyncRoot level="debug" includeLocation="false">
            		<AppenderRef ref="Socket"/>
      	    </AsyncRoot>	
      		<Root level="debug" includeLocation="false">
      			<AppenderRef ref="Console" />
      		</Root>
      	</Loggers>
      

      Gives console logging, but no logging to the socket.

      Changing the config to:

      	<Loggers>
      		<AsyncRoot level="debug" includeLocation="false">
            		<AppenderRef ref="Socket"/>
      	    </AsyncRoot>	
      		<Logger name="com" level="debug" includeLocation="false">
      			<AppenderRef ref="Console" />
      		</Logger>
      	</Loggers>
      

      Gives both console and socket logging, for "com" and descendants, but code that is logging to another domain than com does not end up in the console.
      I also tried to leave the name empty in the test above, but that doesn't work.

      What's the problem? The documentation, or my understanding of it, or the implementation?

      I would really like to have both asynchronous and synchronous root in the same configuration.

      Attachments

        Activity

          People

            rpopma Remko Popma
            kajbj Kaj Bjurman
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: