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?