Typically one creates an SLF4J logger by calling LoggerFactory.getLogger(<class>) which doesn't allow to set the logging Level unless you create resources file is there a way to create a log4j logger instance with setting level programmatically and then use that as an instance to bind to SLF4j facade?
Add a comment
|
1 Answer
LoggerFactory in org.slf4j package could get the logger factory and let you update it.
I am using the Scala to give you example, java almost the same with Scala.
import ch.qos.logback.classic.{Level, Logger, LoggerContext}
import org.slf4j.LoggerFactory
val loggerContext: LoggerContext = LoggerFactory.getILoggerFactory.asInstanceOf[LoggerContext]
val rootLogger: Logger = loggerContext.getLogger("root")
def setLevel(level: String) = {
rootLogger.setLevel(Level.toLevel(level))
}