How to enable debug in slf4j Logger?

后端 未结 9 586
醉酒成梦
醉酒成梦 2020-12-24 05:21

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

相关标签:
9条回答
  • 2020-12-24 05:44

    Just add the following to the application.properties

    logging.level.org.springframework.web=DEBUG
    logging.level.org.springframework.context=DEBUG
    
    0 讨论(0)
  • 2020-12-24 05:46

    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);
    }
    
    0 讨论(0)
  • 2020-12-24 05:49

    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>
    
    0 讨论(0)
提交回复
热议问题