How to globally enable debug
for all the slf4j.Logger
objects?

- 90,905
- 62
- 285
- 365
-
3slf4j is an API. You need to configure the implementation ("binding") behind the API. – Thorbjørn Ravn Andersen Jun 01 '12 at 09:58
-
1@PeterRader, struggling to recollect that after 5 years. Soz, mate. – missingfaktor Mar 09 '17 at 15:43
-
2Sorry to ping such an old question, but I just want to cross-link https://stackoverflow.com/questions/14544991/how-to-configure-slf4j-simple which I found useful for configuring slf4j-simple to do the above. – Jon Sampson Jan 23 '20 at 14:46
10 Answers
Programmatically, with logback:
setLoggingLevel(ch.qos.logback.classic.Level.DEBUG);
where
public static void setLoggingLevel(ch.qos.logback.classic.Level level) {
ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) org.slf4j.LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
root.setLevel(level);
}

- 321,522
- 82
- 660
- 783
-
34Can I kiss you!?!!!? I have been searching how to disable this bloody logging in spring since 1 hour!!!!!!!!!!!!!!!! – EralpB Jan 30 '17 at 14:33
-
Does that only work if logback is your "backing" logging api? I thought slf4j was going to make a facility for this. – Constance Eustace Apr 04 '18 at 14:23
-
exists various capability to switch debug log on:
this article have good explanation all of those. to me good fit is:
Using slf4j with Log4j logger
create file src/main/resources/log4j.properties
log4j.rootLogger=DEBUG, STDOUT
log4j.logger.deng=INFO
log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
log4j.appender.STDOUT.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

- 5,649
- 2
- 37
- 37
-
3
-
7Actually, it is. It defines INFO as the level for all classes/Loggers under package `package deng;`. A more natural example line would be `log4j.logger.org.faceless.product.magic=INFO` with a reversed FQCN, which is more common. – mgaert May 30 '17 at 12:24
Pass the System Property -Dorg.slf4j.simpleLogger.defaultLogLevel=DEBUG at your Java startup for the SLF4J Simple api

- 315
- 5
- 11
-
So strange that this is not mentioned in the official SLF4J documents. – Cagin Uludamar Apr 13 '23 at 09:16
Use logback as the slf4j binding.
The default behaviour without an configuration file is to log all events at level DEBUG and above to System.out. See http://logback.qos.ch/manual/configuration.html#automaticConf for details.

- 73,784
- 33
- 194
- 347
-
3"Use logback as the slf4j binding." I am a noob. Can you please tell me how to do this? My google fu is failing me atm. – missingfaktor Jun 01 '12 at 10:53
-
Remove your current binding (see http://www.slf4j.org/faq.html#where_is_binding) and put logback-classic in your classpath. – Thorbjørn Ravn Andersen Jun 01 '12 at 11:00
If you are using slf4j with springboot, you just need to set debug level in application.properties
.
logging.level.root=DEBUG
You also can set the specific part by setting logging.group
.
Image that, if you have com.pxample
, com.example
, com.dxample
in src/main/java/
and you setting:
logging.group.mycustomgroup=com.pxample, com.example
logging.level.mycustomgroup=DEBUG
, then only com.pxample
, com.example
will show debug output for you.

- 3,638
- 8
- 47
- 84
Just add the following to the application.properties
logging.level.org.springframework.web=DEBUG
logging.level.org.springframework.context=DEBUG

- 121
- 2
- 8
depends on what binding you are using... if e.g. it's log4j have a look at http://logging.apache.org/log4j/1.2/manual.html and its Configuration chapter

- 5,191
- 1
- 29
- 43
If you use log4j as the binding of slf4j you can crete a log4j.xml (or log4j.properties) file and add it to the classpath. An example could be:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<param name="Threshold" value="DEBUG" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{1}] %m%n" />
</layout>
</appender>
<root>
<appender-ref ref="CONSOLE" />
</root>
</log4j:configuration>

- 6,069
- 1
- 33
- 46
For log4j
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">
<!-- ============================== -->
<!-- Append messages to the console -->
<!-- ============================== -->
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out"/>
<param name="Threshold" value="INFO"/>
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n"/>
</layout>
</appender>
<appender name="web" class="org.apache.log4j.DailyRollingFileAppender">
<param name="Threshold" value="DEBUG"/>
<param name="Append" value="true"/>
<param name="File" value="${catalina.home}/logs/web.log"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n"/>
</layout>
</appender>
<category name="com.idc.scd" additivity="false">
<priority value="${log4j.category.com.mypackage}"/>
<appender-ref ref="web"/>
</category>
</log4j:configuration>
by this cofiguration your all "com.mypackage" logs will be written in "web.log" file under catalina.home.

- 73,784
- 33
- 194
- 347

- 7,914
- 5
- 28
- 37
-
1Can you please suggest an alternative logging library where I won't have to add XML configuration files, and where debug/info/error are all enabled by default? – missingfaktor Jun 01 '12 at 09:27
-
along with xml Log4j also provides java classes where you can add your log4jconfigurations. – Pramod Kumar Jun 01 '12 at 09:33
-
I mean, is there a library that requires me to provide no configuration and has sane/expected defaults? – missingfaktor Jun 01 '12 at 09:34
-
You can use java logging API which provides following log levels -SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST. – Pramod Kumar Jun 01 '12 at 09:37
Here's a sample configuration I usually use to setup logging with logback.
Gradle dependencies (the same apply to Maven)
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
logback.xml
configuration to be placed in the project's classpath (src/main/resources)
<configuration>
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M\(%line\) - %msg%n</Pattern>
</layout>
</appender>
<!-- enable debug only on org.hibernate.SQL package -->
<logger name="org.hibernate.SQL" level="debug" additivity="false">
<appender-ref ref="STDOUT" />
</logger>
<root level="info">
<appender-ref ref="STDOUT" />
</root>
</configuration>

- 1,453
- 1
- 14
- 22