Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weird logs from log4j2

I'm running an application in Tomcat 8 which uses log4j2. Everything works, but whenever I try to log something, the following message appears in Tomcat's stderr:

ERROR Unable to create Lookup for web java.lang.ClassCastException: class org.apache.logging.log4j.web.WebLookup
    at java.lang.Class.asSubclass(Class.java:3396)
    at org.apache.logging.log4j.core.lookup.Interpolator.<init>(Interpolator.java:64)
    at org.apache.logging.log4j.core.config.PropertiesPlugin.configureSubstitutor(PropertiesPlugin.java:57)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:135)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:766)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:706)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:339)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:161)
    at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:359)
....

what's that all about?

As I said, everything works perfectly, but I would prefer not seeing this message, as it looks like something has gone wrong.

like image 434
SMSk Avatar asked Mar 18 '15 11:03

SMSk


2 Answers

You are probably missing the log4j-web dependency

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-web</artifactId>
    <version>2.16.0</version>
</dependency>
like image 76
David Rabinowitz Avatar answered Sep 28 '22 05:09

David Rabinowitz


This error may also happen when the configuration points to a non-existing configuration file.

In my case, the web.xml contained an init-param log4jConfiguration defining a Log4J configuration file that was not yet placed on the server.

like image 40
Stapelüberlaufnutzer Avatar answered Sep 28 '22 03:09

Stapelüberlaufnutzer