How to disable Spring logging DEBUG messages?

Spring uses commons-logging which auto-detects the logging framework to use. There are various ways to tune which logging framework will be chosen so the first thing to do is to make sure commons-logging binds to log4j.

To do that, start your application with an additional flag -Dorg.apache.commons.logging.diagnostics.dest=STDOUT that will output the result of the discovery process.

commons-logging delegate to log4j

You now need to make sure that log4j is initialise with the expected configuration. By default, log4j searches for a log4j.xml file at the root of the classpath and fallbacks to log4j.properties if it does not find one. It could be possible that one of the library you are using has (wrongly) a log4j.xml file at the root.

To debug log4j, run your application again with an additional flag -Dlog4j.debug=true. This will output the exact loggers and the location of the configuration file.

commons-logging does not delegate to log4j

If commons-logging does not delegate to log4j, this means that another logging framework is involved. The most common scenario is that your application ships with jcl-over-slf4j.jar, a drop-in replacement of commons-logging that uses slf4j behind the scene.

In this scenario, Spring uses commons-logging that is configured to delegate to slf4j. So, essentially, Spring is using slf4j. But slf4j is a simple logging facade and needs a binding to an actual framework.

SINCE 1.6.0 If no binding is found on the class path, then SLF4J will default to a no-operation implementation.

Once you have found the binding library (it could be logback or log4j for instance), check the configuration of the logging framework that slf4j is bound to.

In this particular case, you probably have logback in your classpath. As it is a pure implementation of slf4j, it does not need a binding library and it logs in debug if no configuration file is provided, which matches your problem actually. To fix your issue, exclude logback from your dependencies and add slf4j-log4j12 to configure slf4j with log4j.


Edit: updated with various comments


You can disable all debug logs by just calling the below code at start of your application. And you can enable or disable at any point of time by setting log type.

ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
logger.setLevel(Level.toLevel("error"));