如何在spring

时间:2016-05-18 12:31:52

标签: java spring

如何在我的spring应用程序中禁用调试模式。当我在生产中运行我的应用程序时,它会提供大量调试日志语句,并且tomcat的日志文件占用磁盘空间。如下,

05:03:26.340 [http-bio-1880-exec-2] DEBUG o.s.s.w.a.ExceptionTranslationFilter - Chain processed normally
05:03:26.340 [http-bio-1880-exec-2] DEBUG o.s.s.w.c.SecurityContextPersistenceFilter - SecurityContextHolder now cleared, as request processing completed
05:03:30.118 [http-bio-1880-exec-2] DEBUG o.s.s.w.u.m.AntPathRequestMatcher - Checking match of request : '/myRestCall/1234'; against '/'
05:03:30.118 [http-bio-1880-exec-2] DEBUG o.s.security.web.FilterChainProxy - /myRestCall/1234 at position 1 of 8 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter'
05:03:30.118 [http-bio-1880-exec-2] DEBUG o.s.s.w.c.HttpSessionSecurityContextRepository - No HttpSession currently exists
05:03:30.118 [http-bio-1880-exec-2] DEBUG o.s.s.w.c.HttpSessionSecurityContextRepository - No SecurityContext was available from the HttpSession: null. A new one will be created.
05:03:30.118 [http-bio-1880-exec-2] DEBUG o.s.security.web.FilterChainProxy - /myRestCall/1234 at position 2 of 8 in additional filter chain; firing Filter: 'WebAsyncManagerIntegrationFilter'
05:03:30.118 [http-bio-1880-exec-2] DEBUG o.s.security.web.FilterChainProxy - /myRestCall/1234 at position 3 of 8 in additional filter chain; firing Filter: 'CustomUserNamePasswordAuthenticationFilter'
05:03:30.118 [http-bio-1880-exec-2] DEBUG o.s.security.web.FilterChainProxy - /myRestCall/1234 at position 4 of 8 in additional filter chain; firing Filter: 'RequestCacheAwareFilter'
05:03:30.118 [http-bio-1880-exec-2] DEBUG o.s.security.web.FilterChainProxy - /myRestCall/1234 at position 5 of 8 in additional filter chain; firing Filter: 'SecurityContextHolderAwareRequestFilter'
05:03:30.118 [http-bio-1880-exec-2] DEBUG o.s.security.web.FilterChainProxy - /myRestCall/1234 at position 6 of 8 in additional filter chain; firing Filter: 'SessionManagementFilter'
05:03:30.118 [http-bio-1880-exec-2] DEBUG o.s.security.web.FilterChainProxy - /myRestCall/1234 at position 7 of 8 in additional filter chain; firing Filter: 'ExceptionTranslationFilter'
05:03:30.118 [http-bio-1880-exec-2] DEBUG o.s.security.web.FilterChainProxy - /myRestCall/1234 at position 8 of 8 in additional filter chain; firing Filter: 'FilterSecurityInterceptor'
05:03:30.118 [http-bio-1880-exec-2] DEBUG o.s.s.w.a.i.FilterSecurityInterceptor - Public object - authentication not attempted
05:03:30.118 [http-bio-1880-exec-2] DEBUG o.s.security.web.FilterChainProxy - /myRestCall/1234 reached end of additional filter chain; proceeding with original 

这是我的依赖

            <!-- logging into console -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>1.7.5</version>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-core</artifactId>
        <version>1.0.13</version>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.0.13</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>log4j-over-slf4j</artifactId>
        <version>1.7.5</version>           
    </dependency>

如何禁用所有调试日志,我只想显示警告和异常日志。

根据结果我创建了logback.xml(src / main / resources / config / logback.xml)文件,如下所示,

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <!-- encoders are assigned the type
         ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
    <encoder>
      <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
  </appender>
<logger name="org.springframework" level="ERROR"/>
  <root level="ERROR">
    <appender-ref ref="STDOUT" />
  </root>
</configuration>

但仍然DEBUG在控制台中记录打印。我在哪里做错了?

1 个答案:

答案 0 :(得分:2)

某处(通常在类路径中),您有一个logback.xml configuration文件用于此应用程序,编辑并添加

<logger name="org.springframework" level="WARNING"/>

之前

<root level="XXX">

另请注意,您应该"rotate" your log files来减少磁盘使用量。