2016-05-18 27 views
0

如何在我的彈簧應用程序中禁用調試模式。當我在生產環境中運行我的應用程序時,它提供了很多調試日誌語句和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 

這裏是我的depedency

  <!-- 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 /主/資源/配置/ 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

你嘗試了什麼?看起來像log4j配置 –

+1

它看起來像你正在使用log4j到slf4j橋。什麼是使用log4j/logback/JUL的實際日誌框架。發佈您的日誌框架的配置文件 –

+0

@ekemchitsiga請參閱我的更新問題。 – MMMMS

回答

2

某處(通常在classpath中),你有一個logback.xmlconfiguration文件此應用程序,它添加

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

<root level="XXX"> 

另外請注意,你應該"rotate" your log files減少磁盤使用情況。

+0

請檢查我更新的問題。 – MMMMS

+1

如文檔中所示,文件**必須在src/main/resources中**:http://logback.qos.ch/faq.html#configFileLocation –

+0

它工作正常。謝謝。 – MMMMS