Search code examples
javamavenlog4jlogbackpcap4j

properties file exists, but still getting "WARN No appenders could be found"


I'm using the pcap4j library in my application and when I run it I get:

log4j:WARN No appenders could be found for logger (org.pcap4j.core.NativeMappings).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

I also use log4j in my application:

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.11.1</version>
</dependency>

which is configured in main/resources/log4j2-test.properties:

log4j.rootLogger=INFO, fileLogger
log4j.appender.fileLogger.layout=org.apache.log4j.PatternLayout
log4j.appender.fileLogger.layout.ConversionPattern=%d [%t] %-5p (%F:%L) - %m%n
log4j.appender.fileLogger.File=application.log
log4j.appender.fileLogger=org.apache.log4j.DailyRollingFileAppender
log4j.appender.fileLogger.datePattern='.'yyyy-MM-dd-HH-mm

So the configuration file is there and whatever I change in it it has an effect which means log4j sees it and it works, so I'm quite helpless when I read everywhere that this kind of warning is caused by a missing or wrong config file.

Can it be that the error is in the dependency and I can't do anything about it? If so, is there a way to disable the logging in this dependency completely? Actually this is that I would want in the first place anyway.


Solution

  • That message is from log4j 1, whereas you are using log4j2, therefore it is harmless.

    https://github.com/apache/log4j/blob/trunk/src/main/java/org/apache/log4j/Hierarchy.java

      public
      void emitNoAppenderWarning(Category cat) {
        // No appenders in hierarchy, warn user only once.
        if(!this.emittedNoAppenderWarning) {
          LogLog.warn("No appenders could be found for logger (" +
               cat.getName() + ").");
          LogLog.warn("Please initialize the log4j system properly.");
          LogLog.warn("See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.");
          this.emittedNoAppenderWarning = true;
        }
      }