如何在Spring中部署DEBUG日志

时间:2016-01-21 12:19:57

标签: java spring maven tomcat logging

在Tomcat 7上部署我的Spring Boot应用程序时,我有数百条日志。例如:

...
13:08:23.361 [http-apr-8080-exec-4] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'metaDataSourceAdvisor'
13:08:23.375 [http-apr-8080-exec-4] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'requestMappingHandlerAdapter'
13:08:23.375 [http-apr-8080-exec-4] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'mvcConversionService'
13:08:23.375 [http-apr-8080-exec-4] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'mvcPathMatcher'
13:08:23.375 [http-apr-8080-exec-4] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'mvcUrlPathHelper'
13:08:23.376 [http-apr-8080-exec-4] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'mvcUriComponentsContributor'
13:08:23.376 [http-apr-8080-exec-4] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'mvcUriComponentsContributor'
13:08:23.376 [http-apr-8080-exec-4] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration'
...

知道这些日志来自哪里以及如何关闭DEBUG类型的日志?我试过:

  • 在log4j属性文件log4j.rootLogger=INFO中设置,但我认为日志并非来自log4j
  • 设置com.my.app.level = INFO

我的pom.xml

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.0.RELEASE</version>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-ldap</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <!-- deploy on tomcat -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <!-- /deploy on tomcat -->
</dependencies>

我还在应用程序运行时在控制台中获取DEBUG日志

14:31:12.034 [http-apr-8080-exec-6] DEBUG o.s.s.web.DefaultRedirectStrategy - Redirecting to 'http://localhost:8080/myapp/login'
14:31:12.034 [http-apr-8080-exec-6] DEBUG o.s.s.w.c.HttpSessionSecurityContextRepository - SecurityContext is empty or contents are anonymous - context will not
 be stored in HttpSession.
14:31:12.035 [http-apr-8080-exec-6] DEBUG o.s.s.w.c.SecurityContextPersistenceFilter - SecurityContextHolder now cleared, as request processing completed
14:31:12.038 [http-apr-8080-exec-7] DEBUG o.s.security.web.FilterChainProxy - /login at position 1 of 13 in additional filter chain; firing Filter: 'WebAsyncMan
agerIntegrationFilter'
14:31:12.039 [http-apr-8080-exec-7] DEBUG o.s.security.web.FilterChainProxy - /login at position 2 of 13 in additional filter chain; firing Filter: 'SecurityCon
textPersistenceFilter'
14:31:12.040 [http-apr-8080-exec-7] DEBUG o.s.s.w.c.HttpSessionSecurityContextRepository - HttpSession returned null object for SPRING_SECURITY_CONTEXT
14:31:12.040 [http-apr-8080-exec-7] DEBUG o.s.s.w.c.HttpSessionSecurityContextRepository - No SecurityContext was available from the HttpSession: org.apache.cat
alina.session.StandardSessionFacade@695ad515. A new one will be created.
14:31:12.041 [http-apr-8080-exec-7] DEBUG o.s.security.web.FilterChainProxy - /login at position 3 of 13 in additional filter chain; firing Filter: 'HeaderWrite
rFilter'

1 个答案:

答案 0 :(得分:0)

根据您的依赖关系,我可以说您使用的是Logback,而不是Log4j。您可以将其添加到application.properties以关闭春季DEBUG日志:

logging.level.org.springframework = INFO

About the logging framework:

  

默认情况下,如果您使用'Starter POM',将使用Logback   日志记录。还包括适当的Logback路由以确保这一点   使用Java Util Logging,Commons Logging,Log4J的依赖库   或者SLF4J都能正常工作。