2017-02-24 108 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