1

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.

tom
  • 2,137
  • 2
  • 27
  • 51
  • 1
    I would suggest to name the file `log4j2.properties` if located in `src/main/resources`... – khmarbaise Nov 22 '18 at 12:49
  • It made no difference unfortunately. I named it `log4j2-test.properties` according to the [docs](https://logging.apache.org/log4j/2.x/manual/configuration.html) – tom Nov 22 '18 at 13:43

2 Answers2

0

Off topic, sorry :)

You can manually set the log config file using this :

org.apache.log4j.xml.DOMConfigurator.configure("<path>\log4j2-test.properties");

The <path> can either be absolute or relative to the root of your maven module.

TheWildHealer
  • 1,546
  • 1
  • 15
  • 26
0

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;
    }
  }
devwebcl
  • 2,866
  • 3
  • 27
  • 46
  • Thanks, this helped! I didn't know it's coming from an older version. I added the `log4j-1.2-api` bridge as dependency, and disabled the logging for `pcap4j` using a log4j2.xml configuration file with ``. Problem solved. – tom Nov 24 '18 at 17:48