动态更改 log4j 日志级别 [英] Dynamically Changing log4j log level
问题描述
动态更改 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,您应该根据 文档 因为这可以通过实现类来实现.
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() 或类似方法应用程序接口.应用程序应该删除这些.等效功能是在 Log4j 2 implementation classes 中提供,但可能会离开应用程序易受 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屋!