我正在尝试使用 log4j2 日志记录功能配置 Spring(非启动)MVC 项目。目前,我已将所有 *.properties
文件放置在类路径之外的位置。我对此配置使用了 @PropertySource
注释。我收到以下消息
ERROR StatusLogger No Log4j 2 configuration file found.
Using default configuration (logging only errors to the console), or user programmatically provided configurations.
Set system property 'log4j2.debug' to show Log4j 2 internal initialization logging.
See https://logging.apache.org/log4j/2.x/manual/configuration.html for instructions on how to configure Log4j 2
关于我如何以及在哪里做错的任何线索?如果有好的引用资料可供检查,请分享。
最佳答案
将log4j2-web包添加到项目中,然后在web.xml上添加监听器:
<listener>
<listener-class>org.apache.logging.log4j.web.Log4jServletContextListener</listener-class>
</listener>
您可以在此处设置配置路径:
<context-param>
<param-name>log4jConfiguration</param-name>
<param-value>file:///D:/conf/myLogging.xml</param-value>
</context-param>
关于java - Spring MVC + Log4j2 在未识别的类路径位置中定义 log4j2.properties 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51169829/