2017-02-24 107 views
7

我有一個spring啓動應用程序,在初始化logback之前,在啓動時輸出約1500行的JNDI調試日誌記錄到stdout。有誰知道是什麼原因造成的,如果有一種方法可以在此之前獲得logback初始化?我有-Dlogback.debug = true,但沒有多大幫助。在logback被初始化之前的春天JNDI日誌記錄

10:44:56.453 [main] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [java:comp/env/logging.exception-conversion-word] 
10:44:56.457 [main] DEBUG jndi - InitialContextFactory.getInitialContext() 
10:44:56.457 [main] DEBUG jndi - Created initial context delegate for local namespace:[email protected] 
10:44:56.457 [main] DEBUG org.eclipse.jetty.jndi.java.javaURLContextFactory - >>> new root context requested 
10:44:56.457 [main] DEBUG jndi - Looking up name="comp/env/logging.exception-conversion-word" 
10:44:56.457 [main] DEBUG jndi - Trying thread context classloader 
10:44:56.457 [main] DEBUG jndi - Looking up name="env/logging.exception-conversion-word" 
10:44:56.458 [main] DEBUG org.springframework.jndi.JndiLocatorDelegate - Converted JNDI name [java:comp/env/logging.exception-conversion-word] not found - trying original name [logging.exception-conversion-word]. javax.naming.NameNotFoundException; remaining name 'env/logging.exception-conversion-word' 
10:44:56.458 [main] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [logging.exception-conversion-word] 

... 

10:44:56.487 [main] DEBUG jndi - Looking up name="env/LOGGING_PATTERNLEVEL" 
10:44:56.487 [main] DEBUG org.springframework.jndi.JndiLocatorDelegate - Converted JNDI name [java:comp/env/LOGGING_PATTERNLEVEL] not found - trying original name [LOGGING_PATTERNLEVEL]. javax.naming.NameNotFoundException; remaining name 'env/LOGGING_PATTERNLEVEL' 
10:44:56.487 [main] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [LOGGING_PATTERNLEVEL] 
10:44:56.487 [main] DEBUG jndi - InitialContextFactory.getInitialContext() 
10:44:56.487 [main] DEBUG jndi - Created initial context delegate for local namespace:[email protected] 
10:44:56.487 [main] DEBUG jndi - Looking up name="LOGGING_PATTERNLEVEL" 
10:44:56.487 [main] DEBUG org.springframework.jndi.JndiPropertySource - JNDI lookup for name [LOGGING_PATTERNLEVEL] threw NamingException with message: null. Returning null. 
10:44:56,536 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender] 
10:44:56,539 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT] 
10:44:56,543 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property 
10:44:56,561 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender] 
10:44:56,564 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [FILE] 
10:44:56,565 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property 
10:44:56,571 |-INFO in [email protected] - Will use the pattern /tmp/logs/qs.%d{yyyyMMdd-HHmmss}.log to archive files 
10:44:56,574 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - Active log file name: /tmp/logs/qs.log 
10:44:56,574 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - File property is set to [/tmp/logs/qs.log] 
10:44:56,576 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to WARN 
10:44:56,576 |-INFO in [email protected] - Propagating WARN level on Logger[ROOT] onto the JUL framework 
10:44:56,576 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [FILE] to Logger[ROOT] 
10:44:56,576 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT] 
10:44:56,576 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration. 
10:44:56,577 |-INFO in org.s[email protected]32b260fa - Registering current configuration as safe fallback point 

    . ____   _   __ _ _ 
/\\/___'_ __ _ _(_)_ __ __ _ \ \ \ \ 
(()\___ | '_ | '_| | '_ \/ _` | \ \ \ \ 
\\/ ___)| |_)| | | | | || (_| | )))) 
    ' |____| .__|_| |_|_| |_\__, |//// 
=========|_|==============|___/=/_/_/_/ 
:: Spring Boot ::  (v1.4.4.RELEASE) 

10:44:56,750 |-INFO in c.q.l.co.rolling.helper.RenameUtil - Renaming file [/tmp/logs/qs.log] to [/tmp/logs/qs.20170222-173130.log] 
10:44:56 [main] INFO my.Application - Starting ... 
+0

在什麼樣的環境,你運行你的應用程序?它看起來像啓用了JNDI的Jetty。您是使用嵌入式Jetty還是部署戰爭文件? –

+0

我們使用嵌入式碼頭。我們推出像 @SpringBootApplication(scanBasePackages = {...},排除= {...}) @ImportResource( 「類路徑:/spring/foobar-context.xml」) @ServletComponentScan 公共類FoobarApplication擴展SpringBootServletInitializer {0} {0} {0} {0} public static void main(final String [] args){SpringFileApplication.run(FoobarApplication.class,args); } ... } – dlipofsky

+0

這也發生在使用獨立的Tomcat 8.0.33時。下面的「spring.jndi.ignore = true」答案可行,但感覺不好。 – mle

回答

9

我還在使用自定義logback-spring.xml時看到了Spring Boot 1.5.1的這一點。如果logback-spring.xml不存在,則不會顯示調試語句。

我能夠解決它通過禁用JNDIPropertySource。創建一個文件,spring.properties,在classpath根:在https://jira.spring.io/browse/SPR-14026加入

# Disable the JNDIPropertySource. This avoids dozens of spurious DEBUG messages 
# when starting up with a custom logback-spring.xml. We're not alone: 
# http://stackoverflow.com/questions/42446013/spring-jndi-logging-before-logback-is-initialized 
spring.jndi.ignore=true 

spring.jndi.ignore。

這種方法感覺很squ,,但由於我沒有運行JNDI的容器,所以它不會破壞我的任何東西。

+0

這適用於我。您也可以使用-D標誌來設置它,但該文件對我的目的更好。 – dlipofsky

+0

萬一其他人遇到此問題。當我把配置放在spring.properties中時,這個改變適用於我,但是當我把它放在bootstrap.properties中時並不適用。 –

2

我也有同樣的問題,但我無法關閉jndi,因爲我的應用程序正在啓動時使用它。因此,一些研究之後,我結束瞭解決方案:

1)重命名logback-spring.xml一些其他名稱,例如logback-config.xml

2)把logging.config財產成application.properties文件。

因此,您的配置僅適用於彈簧啓動,並且此調試日誌記錄將被跳過。另外在我的情況下,第一個解決方案不工作,因爲我需要jndi,在這種情況下,你也離開jndi啓用。

更新:這有助於僅適用於當地的環境,使遠程的tomcat相同的工作,並刪除catalina.log文件將該調試日誌,我結束了這個重命名的log​​back文件logback.xml,因此它的發現在啓動之前,在jndi查找之前。

-1

您可以通過避免這種此行添加到您的logback xml文件

<logger name="org.springframework.jndi" level="INFO" /> 
+0

不,你不能,因爲這些消息在logback被初始化之前得到記錄。默認情況下,我的logback已設置爲WARN閾值。 – dlipofsky