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

Combining Root and AsyncRoot in Xml configuration



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


      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:

      "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">
      		<Console name="Console" target="SYSTEM_OUT">
      			<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
      		<Socket name="Socket" host="localhost" port="666" immediateFail="false" immediateFlush="true" reconnectionDelayMillis="5000">
      			<SerializedLayout />
      		<Root level="debug" includeLocation="false">
      			<AppenderRef ref="Console" />
      		<AsyncRoot level="debug" includeLocation="false">
            		<AppenderRef ref="Socket"/>

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

      Changing the order of the root elements to:

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

      Gives console logging, but no logging to the socket.

      Changing the config to:

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

      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.




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