简体   繁体   English

Spring MVC + Log4j2 在未识别的类路径位置中定义 log4j2.properties 文件

[英]Spring MVC + Log4j2 defining log4j2.properties file in none class path location not identified

I'm trying to configure Spring (non boot) MVC project with log4j2 logging capabilities.我正在尝试使用 log4j2 日志记录功能配置 Spring(非启动)MVC 项目。 Currently I've placed all *.properties files in a location that is not in the class path.目前我已将所有*.properties文件放在不在类路径中的位置。 I've used @PropertySource annotation for this configuration.我在这个配置中使用了@PropertySource注释。 I'm getting below message我收到以下消息

ERROR StatusLogger No Log4j 2 configuration file found.错误 StatusLogger 未找到 Log4j 2 配置文件。
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.设置系统属性“log4j2.debug”以显示 Log4j 2 内部初始化日志记录。
See https://logging.apache.org/log4j/2.x/manual/configuration.html for instructions on how to configure Log4j 2有关如何配置 Log4j 2 的说明,请参阅https://logging.apache.org/log4j/2.x/manual/configuration.html

Any clue on how and where I've done wrong?关于我如何以及在哪里做错的任何线索? if there are good references to check please do share.如果有好的参考资料可以检查,请分享。

Add log4j2-web package into project, and then add listener on web.xml:将 log4j2-web 包添加到项目中,然后在 web.xml 上添加侦听器:

<listener>
    <listener-class>org.apache.logging.log4j.web.Log4jServletContextListener</listener-class>
</listener>

and you can set configure path here:你可以在这里设置配置路径:

<context-param>
    <param-name>log4jConfiguration</param-name>
    <param-value>file:///D:/conf/myLogging.xml</param-value>
</context-param>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM