Here i am going to show how to change the log level in logback logging api at runtime.
Following are the possible log level available in logback.
- TRACE
- DEBUG
- INFO
- WARN
- ERROR
Below is the set of code if it gets executed will changes the level to the one it is being set.
First retrieve the LoggerContext using LoggerFactory, then retrieve the root logger or you can retrieve any specific
logger as well.
After getting the rootLogger then call setLevel method to specify the new log level.
LoggerContext loggerContext = (LoggerContext)LoggerFactory.getILoggerFactory(); Logger rootLogger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME); ((ch.qos.logback.classic.Logger) rootLogger).setLevel(Level.DEBUG);
No comments:
Post a Comment