我遇到Spring Boot将DEBUG级别日志项目吐出到终端时遇到问题,当它应该处于INFO级别时。
logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<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} - %msg%n</Pattern>
</layout>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
<logger name="org.springframework.web" level="WARN"/>
</configuration>
pom.xml中的依赖关系 (省略了所有不涉及日志记录的内容)
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Logging -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
</dependencies>
不断显示在终端中的行
20:01:00.937 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'serverServletmapping' in [servletConfigInitParams]
20:01:00.937 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'serverServletmapping' in [servletContextInitParams]
20:01:00.937 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'serverServletmapping' in [systemProperties]
20:01:00.937 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'serverServletmapping' in [systemEnvironment]
20:01:00.937 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'serverServletmapping' in [random]
20:01:00.937 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'serverServletmapping' in [applicationConfig: [classpath:/application.properties]]
20:01:00.938 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'serverServletmapping' in [class path resource [sql.properties]]
20:01:00.938 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'serverServletmapping' in [localProperties]
20:01:00.938 [main] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Could not find key 'serverServletmapping' in any property source. Returning [null]
20:01:00.938 [main] DEBUG o.s.core.env.MutablePropertySources - Adding [servletConfigInitParams] PropertySource with lowest search precedence
20:01:00.938 [main] DEBUG o.s.core.env.MutablePropertySources - Adding [servletContextInitParams] PropertySource with lowest search precedence
20:01:00.938 [main] DEBUG o.s.core.env.MutablePropertySources - Adding [systemProperties] PropertySource with lowest search precedence
20:01:00.938 [main] DEBUG o.s.core.env.MutablePropertySources - Adding [systemEnvironment] PropertySource with lowest search precedence
20:01:00.938 [main] DEBUG o.s.core.env.MutablePropertySources - Adding [random] PropertySource with lowest search precedence
20:01:00.938 [main] DEBUG o.s.core.env.MutablePropertySources - Adding [applicationConfig: [classpath:/application.properties]] PropertySource with lowest search precedence
20:01:00.938 [main] DEBUG o.s.core.env.MutablePropertySources - Adding [class path resource [sql.properties]] PropertySource with lowest search precedence
答案 0 :(得分:0)
看起来logback没有找到您的logback.xml
文件。请参阅logback documentation on config file location。
logback.groovy
,logback-test.xml
或logback.xml
等配置文件可以直接位于类路径中声明的任何文件夹下。例如,如果类路径为c:/java/jdk15/lib/rt.jar;c:/mylibs/
,则logback.xml
文件应位于c:/mylibs/
的正下方,即c:/mylibs/logback.xml
。将其放在
c:/mylibs/
的子文件夹下,例如c:/mylibs/other/
,将无效。对于Web应用程序,配置文件可以直接放在WEB-INF / classes / 下
。
答案 1 :(得分:0)
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level>
</filter>
<encoder>
<pattern>%d{HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>
添加此过滤器