LogManager.getLogger() 无法确定 Java 11 上的类名
我正在将log4j2(2.11.1)与Java 11一起使用,并尝试使用以下方法获取对象:Logger
private static final Logger LOG = LogManager.getLogger();
(从 中导入log4j-api
org.apache.logging.log4j
)
在运行时,我收到以下错误:
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)
这确实有意义 - getCallerClass不受支持,因此记录器无法确定类名。
它应该以这种方式工作吗?当然,我不必将类名硬编码到每个记录器中?