I'm using log4j2 (2.11.1) with Java 11 and attempting to get a Logger
object using:
private static final Logger LOG = LogManager.getLogger();
(Imported from log4j-api
in org.apache.logging.log4j
)
At runtime, I receive the following error:
WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performance.
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.UnsupportedOperationException: No class provided, and an appropriate one cannot be found.
at
org.apache.logging.log4j.LogManager.callerClass(LogManager.java:555)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:580)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:567)
at app.App.<clinit>(App.java:11)
Which does make sense - getCallerClass is not supported and so the logger is unable to determine the class name.
Is it supposed to work this way? Surely I don't have to hard-code the class name into each logger?
log4j2 (2.11.1)
? – SubdeaconStackWalker.getCallerClass()
, has been introduced with Java 9. According to the changelogs, support for it has been added even in log4j2 2.9.0. Perhaps, you need a build specifically for Java 9+… – Crow../.m2/repository/org/apache/logging/log4j/log4j-api/2.11.1/log4j-api-2.11.1.jar!/META-INF/versions/9/org/apache/logging/log4j/util/StackLocator.class
– Subdeacon