java - 如何在 Spring 中关闭部署 DEBUG 日志

标签 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'

最佳答案

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

logging.level.org.springframework = INFO

About the logging framework:

By default, If you use the ‘Starter POMs’, Logback will be used for logging. Appropriate Logback routing is also included to ensure that dependent libraries that use Java Util Logging, Commons Logging, Log4J or SLF4J will all work correctly.

关于java - 如何在 Spring 中关闭部署 DEBUG 日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34923663/

相关文章:

java - 无法运行 JBehave 故事

java - 如何运行 Maven 站点以及正常的安装/打包目标

java - 在 hibernate 中设置 allowOutOfTransactionUpdateOperations 属性

java - 在java中缩放多页TIFF图像

java - 线程的客户端/服务器问题。端口已绑定(bind)

java - 管理 Spring 异步任务执行器中特定方法的线程执行数量

java - SpringApplicationBuilder用于组合小型SpringBoot应用程序(模块化Monolith)

java - 显示 JSP 内渲染的 Spring Boot buildInfo() 版本

java - Spring Boot中如果同时出现多个请求,如何保持多个请求?

scala - 输出路径在同一模块之间共享错误