Radim Vansa
Radim Vansa

Reputation: 5888

log4j2 wrapped by JBoss logging

I have an app using three libraries:

  1. first uses JBoss logging
  2. second uses Apache Commons' logging
  3. third uses directly log4j2 API if it is on the classpath (or log4j if it is not)

and was configured to route the logging into log4j 1.2.

I want to switch to log4j2 because of performance issues.

I have removed log4j from classpath and added log4j2-1.2-bridge, log4j2-core and log4j2-api there. I have configured the logging via -Dlog4j.configurationFile with configuration similar to following:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
   <Appenders>
      <Console name="CONSOLE" target="SYSTEM_OUT">
         <PatternLayout pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %m%n"/>
      </Console>
   </Appenders>
   <Loggers>
      <Logger name="foo" level="TRACE">
         <AppenderRef ref="CONSOLE"/>
      </Logger>

      <Logger name="foo.bar" level="DEBUG">
         <AppenderRef ref="CONSOLE"/>
      </Logger>
      <Logger name="xxx" level="TRACE">
         <AppenderRef ref="CONSOLE"/>
      </Logger>
      <Root level="DEBUG">
         <AppenderRef ref="CONSOLE"/>
      </Root>
  </Loggers>
</Configuration>

Now, I have several problems:

  1. Messages coming from Apache Commons logging are logged twice
  2. Messages i18ed by JBoss logging (via logger created from annotations) are not formatted according to the configuration, but use default log4j2 format instead. However, these are written only once.
  3. There are few non-i18ed messaged from the JBoss logging logged by one specific class, but not all (this is really weird)
  4. Messages coming from direct use of the log4j2 API are logged two to three times

Any hints how to fix those?

Upvotes: 1

Views: 3465

Answers (1)

Radim Vansa
Radim Vansa

Reputation: 5888

So I did basically two mistakes:

  1. I haven't spotted the additivity used in log4j2 logging - each logger has to have additivity="false" (could this be set somehow globally?)
  2. My jboss-logging version was 3.1.2.GA, where, regrettably, usage of log4j2 was not fixed yet (see JBLOGGING-94). It was fixed only in non-released version 3.1.4.GA, so I have to use the SNAPSHOT version (and cannot release my app with log4j2 support).

Upvotes: 2

Related Questions