动态更改log4j日志级别 [英] Dynamically Changing log4j log level

查看:120
本文介绍了动态更改log4j日志级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

动态更改log4j日志级别的不同方法有哪些,因此我不必重新部署应用程序。在这些情况下,这些变化是永久性的吗?

What are the different approaches for changing the log4j log level dynamically, so that I will not have to redeploy the application. Will the changes be permanent in those cases?

推荐答案

更改日志级别很简单;修改配置的其他部分将提供更深入的方法。

Changing the log level is simple; modifying other portions of the configuration will pose a more in depth approach.

LogManager.getRootLogger().setLevel(Level.DEBUG);

这些更改在 Logger 。在重新初始化时,将读取并使用配置,因为在运行时设置级别不会持续更改级别。

The changes are permanent through the life cyle of the Logger. On reinitialization the configuration will be read and used as setting the level at runtime does not persist the level change.

更新:如果您正在使用Log4j 2您应该根据 setLevel 的调用>文档,因为这可以通过实现类来实现。

UPDATE: If you are using Log4j 2 you should remove the calls to setLevel per the documentation as this can be achieved via implementation classes.


调用logger.setLevel()或类似的方法不是
API支持。应用程序应删除这些。 Log4j 2实现类中提供的等效功能是
,但可能使
应用程序容易受到Log4j 2内部变化的影响。

Calls to logger.setLevel() or similar methods are not supported in the API. Applications should remove these. Equivalent functionality is provided in the Log4j 2 implementation classes but may leave the application susceptible to changes in Log4j 2 internals.

这篇关于动态更改log4j日志级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆