No appenders could be found for logger(log4j)?

前端 未结 30 2314
[愿得一人]
[愿得一人] 2020-11-22 08:16

I have put log4j to my buildpath, but I get the following message when I run my application:

log4j:WARN No appenders could be found for logger (dao.hsqlmanag         


        
30条回答
  •  灰色年华
    2020-11-22 08:54

    For me, the reason was apparently different, and the error message misleading.

    With just this in my build.gradle, it would complain that slf4j was missing at the beginning of the log, but still log things, albeit in a poor format:

        compile 'log4j:log4j:1.2.17'
    

    Adding that dependency would cause the discussed "no appenders could be found" error message for me, even though I had defined them in src/main/java/log4j.properties:

        compile 'log4j:log4j:1.2.17'
        compile 'org.slf4j:slf4j-log4j12:1.7.25'
    

    Finally, adding the following dependency (which I only guessed at by copycatting it from another project) resolved the issue:

        compile 'log4j:log4j:1.2.17'
        compile 'org.slf4j:slf4j-log4j12:1.7.25'
        compile 'commons-logging:commons-logging:1.2'
    

    I don't know why, but with this it works. Any insights on that?

提交回复
热议问题