简体   繁体   English

Log4j1.x 迁移到 log4j2 java

[英]Log4j1.x migration to log4j2 java

I have upgraded log4j1.x version to log4j2.17, I observed that some of new logs are printing on my console/server.log which might be from other jars I am using (eg updating server status in database)我已经将 log4j1.x 版本升级到 log4j2.17,我观察到一些新日志正在打印在我的 console/server.log 上,这可能来自我正在使用的其他 jar(例如更新数据库中的服务器状态)

How can I restrict stdout in my console or server.log如何在我的控制台或 server.log 中限制标准输出

I have added console appender in my log4j2.xml我在我的 log4j2.xml 中添加了控制台附加程序

While this looks like a bad idea - you would want important logs from dependencies to be a part of your log for debugging issues, here is the way to do it.虽然这看起来像个坏主意——您可能希望来自依赖项的重要日志成为调试问题日志的一部分,但这是实现此目的的方法。

In log4j.properties file, you can set the root logger to ERROR.log4j.properties文件中,您可以将根记录器设置为 ERROR。 Then for the your own application, you can override the now default ERROR to INFO/DEBUG.然后对于您自己的应用程序,您可以将现在默认的 ERROR 覆盖为 INFO/DEBUG。

log4j.rootLogger=ERROR, stdout
log4j.X.Y.Z=DEBUG

Ref - Filtering out log4j messages from third-party frameworks?参考 - 从第三方框架中过滤掉 log4j 消息?

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

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