0

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?

1 Answer 1

1

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))
}


Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.