Reputation: 3232
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!");
Upvotes: 1
Views: 649
Reputation: 1108
Get the logger names from LogManager.getCurrentLoggers()
and then set the LogManager.getLogger("<name from loop>").setLevel(Level.FATAL)
; using loop.
When you are getting LogManager.getRootLogger()
gets the root level logger. It is not going to affect all the individual configuration.
Upvotes: 2