1
votes

Our console application is using logback for logging. There's a logback.xml file in the classpath.

Logging works as expected (via logback) on most platforms (Linux, Windows, jdk7 or jdk8).

However, on Macs using jdk 6, when running the app we sometimes see:

log4j:WARN No appenders could be found for logger (our.class.Here).
log4j:WARN Please initialize the log4j system properly.

It seems for some reason log4j is chosen for logging instead of logback. In our.class.Here we log through slf4j:

private static final org.slf4j.Logger LOG = org.slf4j.LoggerFactory.getLogger(our.class.Here.class);

This is the complete classpath:

/path/etc/logback.xml:/path/lib/pdfbox-1.8.4.jar:/path/lib/fontbox-1.8.4.jar:/path/lib/jempbox-1.8.4.jar:/path/lib/jcl-over-slf4j-1.7.7.jar:/path/lib/bcprov-jdk15-1.45.jar:/path/lib/bcmail-jdk15-1.45.jar:/path/lib/xmlgraphics-commons-1.5.jar:/path/lib/icepdf-core-5.0.4.jar:/path/lib/jai-codec-1.1.3.jar:/path/lib/jai-core-1.1.3.jar:/path/lib/jewelcli-0.6.jar:/path/lib/commons-lang3-3.1.jar:/path/lib/commons-io-2.2.jar:/path/lib/logback-classic-1.1.0.jar:/path/lib/logback-core-1.1.0.jar:/path/lib/itext-2.1.7.jar:/path/lib/hibernate-validator-4.2.0.Final.jar:/path/lib/slf4j-api-1.7.5.jar

How could we troubleshoot further to understand why log4j instead of logback is chosen for logging?

Thanks for your suggestions.

2
Are you running your app standalone or within a container?Sotirios Delimanolis
It's a standalone console applicationEdi

2 Answers

1
votes

I don't see log4j-over-slf4j in your classpath... perhaps that's what you're missing to ensure any log4j related code goes through the proper slf4j logging impl (logback)?

  <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>log4j-over-slf4j</artifactId>
    <version>1.7.10</version>
  </dependency>
1
votes

The problem was that log4j.jar was in the user's Java's Extensions directory: /Library/Java/Extensions

We found this out by running java with -verbose, which pointed out where log4j.jar was loading from.

The workaround was to disable the extensions folder when running our app: export JAVA_OPTS=-Djava.ext.dirs=""

Since the machine was not ours, we could not apply the (better) permanent solution of cleaning up the extension's dir.