动态更改 log4j 日志级别的不同方法是什么,这样我就不必重新部署应用程序了。在这些情况下,这些变化会是永久性的吗?
最佳答案
更改日志级别很简单;修改配置的其他部分将构成更深入的方法。
LogManager.getRootLogger().setLevel(Level.DEBUG);
这些更改在 Logger
的生命周期中是永久性的。重新初始化时,配置将被读取并使用,因为在运行时设置级别不会持久更改级别。
更新:如果您使用 Log4j 2,您应该根据 documentation 删除对 setLevel
的调用。因为这可以通过实现类来实现。
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.
关于java - 动态改变 log4j 日志级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4598702/