18

I am using logback for my logging and it has been working however; the other day I started getting a warning

log4j:WARN No appenders could be found for logger (org.apache.axis.i18n.ProjectResourceBundle). log4j:WARN Please initialize the log4j system properly.

I am not using log4j nor have I ever with this project. I have a logback.xml in my resources folder.

Any ideas on why this warning started to show up?

Chris Watts
  • 2,284
  • 4
  • 23
  • 28

2 Answers2

20

You must be using a library that does use log4j. Can you post anything more about your project?

You should probably just put log4j bridge on the classpath. Read more here: http://www.slf4j.org/legacy.html

The jar you want to look into is log4j-over-slf4j. It will bridge log4j API to actually make calls to your implementation of slf4j API (in your case - logback).

If you are using Maven to build your project then it might be as simple as putting

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>log4j-over-slf4j</artifactId>
    <version>1.7.7</version>
</dependency>

in dependencies.

Excluding a library (if needed) would be done in this fashion (this assumes we are talking about the transitive dependency from the jar you've mentioned):

    <dependency>
        <groupId>org.swift.common</groupId>
        <artifactId>jira-soap</artifactId>
        <version>4.4.0</version>
        <exclusions>
            <exclusion>
                <groupId>...</groupId>
                <artifactId>...</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
theadam
  • 3,961
  • 4
  • 25
  • 41
  • See comment above about jira library that uses axis – Chris Watts Jan 14 '13 at 20:00
  • 4
    ... and excluding any log4j jars that are pulled in as transitive dependencies of anything else. – Ian Roberts Jan 14 '13 at 20:04
  • @Ian - that's correct. Chris - in case if you're unfamiliar with Maven then check out dependencies management section of the docs: http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html (that is only relevant if you are indeed using Maven for this :)) – theadam Jan 14 '13 at 20:20
  • @IanRoberts excluding the log4j dependency that maven auto imported fixed the issue. However, I did not have to add the tag in the pom.xml file instead I just used Intillj's project settings for the libraries included and just removed it from that list. – Chris Watts Jan 14 '13 at 20:52
  • I am still assuming that you are using Maven :) I do see that the artifact you've mentioned uses commons-logging - if you'd need to exclude this dependency you'd do it like I've mentioned in the last part of the edited answer. org.swift.common jira-soap 4.4.0 commons-logging commons-logging – theadam Jan 14 '13 at 20:56
  • @theadam I had the same problem. Very confusing since it told me that Log4j was the problem not commons-logging – Avec Mar 12 '14 at 06:13
  • @theadam although you are mentioning about log4j-over-slf4j, your maven first dependency is slf4j-log4j12 which is not a bridge but rather chanelling slf4j to log4j? Sorry i dont understand – dimitrisli Nov 26 '14 at 10:51
  • @dimitrisli you are right, that was a mistake on my part, I wonder how I never caught it. slf4j-log4j12 is log4j binding for slf4j, I've updated the maven dependency above. Thanks! – theadam Nov 26 '14 at 14:50
9

Took me some time to find out since the message was log4j:WARN No appenders could be found for logger

I tried to exclude log4j and I tried the log4j-over-slf4j.

Then I ran mvn dependency:tree and finally found out that mye commons-configuration actually was using commons-logging

[INFO] +- commons-configuration:commons-configuration:jar:1.9:compile
[INFO] |  \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] +- ch.qos.logback:logback-classic:jar:1.0.13:compile
[INFO] |  +- ch.qos.logback:logback-core:jar:1.0.13:compile
[INFO] |  \- org.slf4j:slf4j-api:jar:1.7.5:compile
[INFO] +- org.slf4j:log4j-over-slf4j:jar:1.7.6:compile
[INFO] \- org.apache.commons:commons-lang3:jar:3.1:compile

This became the solution for me.

    <!-- logging with logback (and slf4j)-->
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.0.13</version>
    </dependency>

    <!-- had a dep in commons-configuration -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>1.7.6</version>
    </dependency>
Avec
  • 1,626
  • 21
  • 31
  • 1
    According to http://www.slf4j.org/legacy.html common-loggings should be removed from the dependency list in pom.xml. – Sharm Jul 05 '21 at 13:14