How to change slf4j level at runtime?

I’ve using SLF4j as my logging framework, backed by log4j. My problem is that I am looking for a way to change the logging level for my logger at runtime.

I understand that slf4j does not permit this directly through its own API, and hence, I have to access the logging provider directly. Personally, I find this to be a huge deficiency in slf4j. So now my question is how can I determine programatically through slf4j which provider I am using? The biggest purpose of using slf4j is that you become provider agnostic – you can easily switch between your favourite logging system without having to recode anything. But now, if I have to make direct calls to log4j, I am losing that ability.

At the very least, I would like to be able to determine if I am using log4j as the provider and if so, then allow the user to switch log levels.

If I do LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME), the result is an instance of org.slf4j.impl.Log4jLoggerAdapter and not even org.apache.log4j.Logger (as I would have hoped/expected).

Is there any way to find this out?

Thanks, Eric

How to dynamically change log level in SLF4j OR Log4J

Recently I encountered a situtation where Application Loglevel changes dynamically. Application Admin can set it to INFO/DEBUG/ WARN from front end. Based on the log level choosen be him application l

Set Dynamic Console Logging Level Using SLF4J

I’m using slf4j logging facade over the jdk built in logger. I’m confused how to set the logging level using a ConsoleHandler for SLF4J. public Class foo(){ Logger log = Logger.getLogger(foo.class())

Failed to change log level of slf4j simplelogger

jdk 6, slf4j 1.7.5 Layout bleow: . ├── com │ └── to │ └── Main.class ├── ├── slf4j-api-1.7.5.jar └── slf4j-simple-1.7.5.jar below: package co

Setting log level of message at runtime in slf4j

When using log4j, the Logger.log(Priority p, Object message) method is available and can be used to log a message at a log level determined at runtime. We’re using this fact and this tip to redirect s

slf4j,change logger or add appender at runtime

I’m using SLF4J for logging (with Log4J). The used appender is configured using an xml. <appender name=business class=org.apache.log4j.RollingFileAppender> <param name=maxFileSize value

How to inject SLF4J bindings with Guice?

After a cursory inspection, it seems like SLF4J and Guice (well, any DI framework, really) are sort of conflicting philosophies. SLF4J takes the approach hey, we won’t know until runtime what classes

SLF4J debugging level configuration + Logging framework integration

I am considering using SLF4j to integrate multiple logging frameworks. The java.util.logging.Logger class has a nice method called setLevel(Level newLevel). It enables logging configuration at a class

SLF4J Log Level as an argument

We are looking to use SLF4J, but one thing we found was that you can’t specify the level as an argument, i.e Logger.log(Level.INFO, messsage); You have to do this; this prev

java.lang.NoClassDefFoundError: org/apache/log4j/Level – slf4j?

I am trying to deploy my application, but it gives me an error: Failed to instantiate SLF4J LoggerFactory Reported exception: java.lang.NoClassDefFoundError: org/apache/log4j/Level at org.slf4j.impl.S

How to suppress SLF4J Warning about multiple bindings?

My java project has dependencies with different SLF4J versions. How do I suppress the annoying warnings? SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:xyz234/li


SLF4J is designed as an abstraction for libraries, not applications (of course, you can and should still use SLF4J in your own app’s logging calls, for consistency). In your own app, you choose the underlying logger framework, so it’s fine to access the log4j API in the logging-config-specific parts.

No way should a library be mucking about with changing the logging config, IMHO, so it’s not appropriate for it to be on the SLF4J API.