Saturday, August 27, 2016

How to change log level in logback at runtime

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

Components of Big Data - Hadoop System

In this blog i will explain important components which are part of Hadoop System. I will give very brief overview of these components. Be...