简体   繁体   English

如何更改所有Log4J 1.x记录器的级别?

[英]How to change level of all Log4J 1.x loggers?

I want to be able to programmatically set the logging level for all loggers. 我希望能够以编程方式为所有记录器设置记录级别。 This works: 这有效:

    Logger log = Logger.getLogger(Example.class);
    LogManager.getLogger(Example.class).setLevel(Level.FATAL);
    log.debug("Should not see!");
    LogManager.getLogger(Example.class).setLevel(Level.DEBUG);
    log.debug("Should see!");

However this does not: 但是,这不是:

    Logger log = Logger.getLogger(Example.class);
    LogManager.getRootLogger().setLevel(Level.FATAL);
    log.debug("Should not see!");
    LogManager.getRootLogger().setLevel(Level.DEBUG);
    log.debug("Should see!");

Get the logger names from LogManager.getCurrentLoggers() and then set the LogManager.getLogger("<name from loop>").setLevel(Level.FATAL) ; LogManager.getCurrentLoggers()获取记录器名称,然后设置LogManager.getLogger("<name from loop>").setLevel(Level.FATAL) ; using loop. 使用循环。

When you are getting LogManager.getRootLogger() gets the root level logger. 在获取LogManager.getRootLogger()将获得根级别的记录器。 It is not going to affect all the individual configuration. 它不会影响所有单个配置。

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

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