将logback.xml放在我的Web应用程序的src / main / resources /文件夹中时,它的工作正常。
然而,当使用LogbackConfigListener在web.xml中)到logback.xml文件的配置位置。日志文件生成成功。
但是,此外,tomcat服务器的控制台上出现了太多的调试日志消息。它延迟了tomcat服务器的启动时间。这些DEBUG消息是Hibernate等第三方库文件的一部分。
logback.xml文件:
<configuration> <!-- Appenders --> <appender name="util" class="ch.qos.logback.core.FileAppender"> <File>${demo.root}/WEB-INF/app.log</File> <Append>true</Append> <encoder> <pattern>%t %-5p %c{2} - %m%n</pattern> </encoder> </appender> <logger name="org.springframework" level="info" /> <root level="info"> <appender-ref ref="util" /> </root> </configuration>
日志跟踪太大。我已经从tomcat服务器的启动窗口中复制了一部分:
00:42:09.422 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Fini shed creating instance of bean '(inner bean)#45' 00:42:09.432 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eage rly caching bean 'org.springframework.security.access.vote.AffirmativeBased#0' t o allow for resolving potential circular references 00:42:09.452 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Invo king afterPropertiesSet() on bean with name 'org.springframework.security.access .vote.AffirmativeBased#0' 00:42:09.459 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Fini shed creating instance of bean 'org.springframework.security.access.vote.Affirma tiveBased#0' 00:42:09.468 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retu rning cached instance of singleton bean 'org.springframework.security.authentica tion.ProviderManager#0' 00:42:09.476 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Crea ting instance of bean '(inner bean)#46' 00:42:09.483 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Crea ting instance of bean '(inner bean)#46' 00:42:09.489 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Fini shed creating instance of bean '(inner bean)#46' 00:42:09.499 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Crea ting instance of bean '(inner bean)#47' 00:42:09.520 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Fini shed creating instance of bean '(inner bean)#47' 00:42:09.525 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retu rning cached instance of singleton bean 'org.springframework.security.web.access .expression.DefaultWebSecurityExpressionHandler#0' 00:42:09.536 [pool-2-thread-1] DEBUG o.s.s.w.a.e.ExpressionBasedFilterInvocation SecurityMetadataSource - Adding web access control expression 'hasRole('ROLE_ADM IN')', for Ant [pattern='/admin.htm'] 00:42:09.633 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Fini shed creating instance of bean '(inner bean)#46' 00:42:09.638 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Invo king afterPropertiesSet() on bean with name 'org.springframework.security.web.ac cess.intercept.FilterSecurityInterceptor#0' 00:42:09.646 [pool-2-thread-1] DEBUG o.s.s.w.a.i.FilterSecurityInterceptor - Val idated configuration attributes 00:42:09.651 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Fini shed creating instance of bean 'org.springframework.security.web.access.intercep t.FilterSecurityInterceptor#0' 00:42:09.660 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Initiali zing new StandardEnvironment 00:42:09.665 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Adding [ systemProperties] PropertySource with lowest search precedence 00:42:09.670 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Adding [ systemEnvironment] PropertySource with lowest search precedence 00:42:09.675 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Initiali zed StandardEnvironment with PropertySources [systemProperties,systemEnvironment ] 00:42:09.684 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Initiali zing new StandardEnvironment 00:42:09.689 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Adding [ systemProperties] PropertySource with lowest search precedence 00:42:09.694 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Adding [ systemEnvironment] PropertySource with lowest search precedence 00:42:09.699 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Initiali zed StandardEnvironment with PropertySources [systemProperties,systemEnvironment ] 00:42:09.708 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Initiali zing new StandardEnvironment 00:42:09.713 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Adding [ systemProperties] PropertySource with lowest search precedence 00:42:09.718 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Adding [ systemEnvironment] PropertySource with lowest search precedence 00:42:09.723 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Initiali zed StandardEnvironment with PropertySources [systemProperties,systemEnvironment ] 00:42:09.732 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Initiali zing new StandardEnvironment 00:42:09.737 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Adding [ systemProperties] PropertySource with lowest search precedence 00:42:09.741 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Adding [ systemEnvironment] PropertySource with lowest search precedence 00:42:09.747 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Initiali zed StandardEnvironment with PropertySources [systemProperties,systemEnvironment ] 00:42:09.755 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Initiali zing new StandardEnvironment 00:42:09.761 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Adding [ systemProperties] PropertySource with lowest search precedence 00:42:09.765 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Adding [ systemEnvironment] PropertySource with lowest search precedence 00:42:09.773 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Initiali zed StandardEnvironment with PropertySources [systemProperties,systemEnvironment ] 00:42:09.782 [pool-2-thread-1] INFO o.s.s.web.DefaultSecurityFilterChain - Crea ting filter chain: org.springframework.security.web.util.AnyRequestMatcher@1, [o rg.springframework.security.web.context.SecurityContextPersistenceFilter@fd9b4d, org.springframework.security.web.authentication.logout.LogoutFilter@1dee0d7, or g.springframework.security.web.authentication.UsernamePasswordAuthenticationFilt er@17b650a, org.springframework.security.web.authentication.www.BasicAuthenticat ionFilter@267b76, org.springframework.security.web.savedrequest.RequestCacheAwar eFilter@73b879, org.springframework.security.web.servletapi.SecurityContextHolde rAwareRequestFilter@1542094, org.springframework.security.web.authentication.rem emberme.RememberMeAuthenticationFilter@26db62, org.springframework.security.web. authentication.AnonymousAuthenticationFilter@10d0630, org.springframework.securi ty.web.session.SessionManagementFilter@114629, org.springframework.security.web. access.ExceptionTranslationFilter@154145, org.springframework.security.web.acces s.intercept.FilterSecurityInterceptor@17035c6] 00:42:09.817 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eage rly caching bean 'org.springframework.security.web.DefaultSecurityFilterChain#1' to allow for resolving potential circular references 00:42:09.826 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Fini shed creating instance of bean 'org.springframework.security.web.DefaultSecurity FilterChain#1' 00:42:09.834 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Invo king afterPropertiesSet() on bean with name 'org.springframework.security.filter Chains' 00:42:09.844 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Fini shed creating instance of bean 'org.springframework.security.filterChains' 00:42:09.851 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Crea ting shared instance of singleton bean 'org.springframework.security.filterChain Proxy' 00:42:09.859 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Crea ting instance of bean 'org.springframework.security.filterChainProxy' 00:42:09.864 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retu rning cached instance of singleton bean 'org.springframework.security.filterChai ns' 00:42:09.874 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Initiali zing new StandardEnvironment 00:42:09.879 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Adding [ systemProperties] PropertySource with lowest search precedence 00:42:09.885 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Adding [ systemEnvironment] PropertySource with lowest search precedence 00:42:09.890 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Initiali zed StandardEnvironment with PropertySources [systemProperties,systemEnvironment ] 00:42:09.897 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Initiali zing new StandardEnvironment 00:42:09.902 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Adding [ systemProperties] PropertySource with lowest search precedence 00:42:09.908 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Adding [ systemEnvironment] PropertySource with lowest search precedence 00:42:09.913 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Initiali zed StandardEnvironment with PropertySources [systemProperties,systemEnvironment ] 00:42:09.921 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Initiali zing new StandardEnvironment 00:42:09.926 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Adding [ systemProperties] PropertySource with lowest search precedence 00:42:09.931 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Adding [ systemEnvironment] PropertySource with lowest search precedence 00:42:09.937 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Initiali zed StandardEnvironment with PropertySources [systemProperties,systemEnvironment ] 00:42:09.950 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Initiali zing new StandardEnvironment 00:42:09.957 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Adding [ systemProperties] PropertySource with lowest search precedence 00:42:09.961 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Adding [ systemEnvironment] PropertySource with lowest search precedence 00:42:09.965 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Initiali zed StandardEnvironment with PropertySources [systemProperties,systemEnvironment ] 00:42:09.973 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Initiali zing new StandardEnvironment 00:42:09.978 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Adding [ systemProperties] PropertySource with lowest search precedence 00:42:09.984 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Adding [ systemEnvironment] PropertySource with lowest search precedence 00:42:09.988 [pool-2-thread-1] DEBUG o.s.core.env.StandardEnvironment - Initiali zed StandardEnvironment with PropertySources [systemProperties,systemEnvironment ] 00:42:10.001 [pool-2-thread-1] DEBUG org.springframework.beans.BeanUtils - No pr operty editor [org.springframework.security.web.SecurityFilterChainEditor] found for type org.springframework.security.web.SecurityFilterChain according to 'Edi tor' suffix convention 00:42:10.017 [pool-2-thread-1] DEBUG o.s.w.c.s.StandardServletEnvironment - Init ializing new StandardServletEnvironment 00:42:10.021 [pool-2-thread-1] DEBUG o.s.w.c.s.StandardServletEnvironment - Addi ng [servletConfigInitParams] PropertySource with lowest search precedence 00:42:10.026 [pool-2-thread-1] DEBUG o.s.w.c.s.StandardServletEnvironment - Addi ng [servletContextInitParams] PropertySource with lowest search precedence 00:42:10.032 [pool-2-thread-1] DEBUG o.s.w.c.s.StandardServletEnvironment - Addi ng [jndiProperties] PropertySource with lowest search precedence 00:42:10.038 [pool-2-thread-1] DEBUG o.s.w.c.s.StandardServletEnvironment - Addi ng [systemProperties] PropertySource with lowest search precedence 00:42:10.044 [pool-2-thread-1] DEBUG o.s.w.c.s.StandardServletEnvironment - Addi ng [systemEnvironment] PropertySource with lowest search precedence 00:42:10.049 [pool-2-thread-1] DEBUG o.s.w.c.s.StandardServletEnvironment - Init ialized StandardServletEnvironment with PropertySources [servletConfigInitParams ,servletContextInitParams,jndiProperties,systemProperties,systemEnvironment] 00:42:10.095 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eage rly caching bean 'org.springframework.security.filterChainProxy' to allow for re solving potential circular references 00:42:10.110 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Crea ting instance of bean '(inner bean)#48' 00:42:10.118 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Fini shed creating instance of bean '(inner bean)#48' 00:42:10.123 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Invo king afterPropertiesSet() on bean with name 'org.springframework.security.filter ChainProxy' 00:42:10.133 [pool-2-thread-1] INFO o.s.s.c.h.DefaultFilterChainValidator - Che cking whether login URL '/login.htm' is accessible with your configuration 00:42:10.146 [pool-2-thread-1] DEBUG o.s.s.web.util.AntPathRequestMatcher - Chec king match of request : '/login.htm'; against '/resources' 00:42:10.154 [pool-2-thread-1] DEBUG o.s.s.web.util.AntPathRequestMatcher - Chec king match of request : '/login.htm'; against '/admin.htm' 00:42:10.158 [pool-2-thread-1] DEBUG o.s.s.c.h.DefaultFilterChainValidator - No access attributes defined for login page URL 00:42:10.164 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Fini shed creating instance of bean 'org.springframework.security.filterChainProxy' 00:42:10.172 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retu rning cached instance of singleton bean 'org.springframework.security.web.Defaul tSecurityFilterChain#0' 00:42:10.180 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retu rning cached instance of singleton bean 'org.springframework.security.web.PortMa pperImpl#0' 00:42:10.187 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retu rning cached instance of singleton bean 'org.springframework.security.web.PortRe solverImpl#0' 00:42:10.195 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retu rning cached instance of singleton bean 'org.springframework.security.config.aut hentication.AuthenticationManagerFactoryBean#0' 00:42:10.202 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retu rning cached instance of singleton bean 'org.springframework.security.authentica tion.ProviderManager#0' 00:42:10.210 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retu rning cached instance of singleton bean 'org.springframework.security.web.contex t.HttpSessionSecurityContextRepository#0' 00:42:10.218 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retu rning cached instance of singleton bean 'org.springframework.security.web.authen tication.session.SessionFixationProtectionStrategy#0' 00:42:10.226 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retu rning cached instance of singleton bean 'org.springframework.security.web.savedr equest.HttpSessionRequestCache#0' 00:42:10.234 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retu rning cached instance of singleton bean 'org.springframework.security.web.access .expression.DefaultWebSecurityExpressionHandler#0' 00:42:10.241 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retu rning cached instance of singleton bean 'org.springframework.security.access.vot e.AffirmativeBased#0' 00:42:10.249 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retu rning cached instance of singleton bean 'org.springframework.security.web.access .intercept.FilterSecurityInterceptor#0' 00:42:10.256 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Crea ting shared instance of singleton bean 'org.springframework.security.web.access. DefaultWebInvocationPrivilegeEvaluator#0' 00:42:10.264 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Crea ting instance of bean 'org.springframework.security.web.access.DefaultWebInvocat ionPrivilegeEvaluator#0' 00:42:10.272 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retu rning cached instance of singleton bean 'org.springframework.security.web.access .intercept.FilterSecurityInterceptor#0' 00:42:10.282 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Eage rly caching bean 'org.springframework.security.web.access.DefaultWebInvocationPr ivilegeEvaluator#0' to allow for resolving potential circular references 00:42:10.298 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Fini shed creating instance of bean 'org.springframework.security.web.access.DefaultW ebInvocationPrivilegeEvaluator#0' 00:42:10.306 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retu rning cached instance of singleton bean 'org.springframework.security.authentica tion.AnonymousAuthenticationProvider#0' 00:42:10.311 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retu rning cached instance of singleton bean 'org.springframework.security.web.authen tication.rememberme.TokenBasedRememberMeServices#0' 00:42:10.319 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retu rning cached instance of singleton bean 'org.springframework.security.authentica tion.RememberMeAuthenticationProvider#0' 00:42:10.326 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retu rning cached instance of singleton bean 'org.springframework.security.web.authen tication.www.BasicAuthenticationEntryPoint#0' 00:42:10.335 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retu rning cached instance of singleton bean 'org.springframework.security.web.authen tication.UsernamePasswordAuthenticationFilter#0' 00:42:10.342 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retu rning cached instance of singleton bean 'org.springframework.security.userDetail sServiceFactory' 00:42:10.350 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retu rning cached instance of singleton bean 'org.springframework.security.web.Defaul tSecurityFilterChain#1' 00:42:10.361 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retu rning cached instance of singleton bean 'org.springframework.security.authentica tion.dao.DaoAuthenticationProvider#0' 00:42:10.376 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retu rning cached instance of singleton bean 'org.springframework.security.authentica tion.DefaultAuthenticationEventPublisher#0' 00:42:10.386 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retu rning cached instance of singleton bean 'org.springframework.security.authentica tionManager' 00:42:10.396 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retu rning cached instance of singleton bean 'org.springframework.context.annotation. ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0' 00:42:10.409 [pool-2-thread-1] DEBUG o.s.w.c.s.XmlWebApplicationContext - Unable to locate LifecycleProcessor with name 'lifecycleProcessor': using default [org .springframework.context.support.DefaultLifecycleProcessor@10cdec1] 00:42:10.421 [pool-2-thread-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retu rning cached instance of singleton bean 'lifecycleProcessor' 00:42:10.429 [pool-2-thread-1] DEBUG o.s.web.context.ContextLoader - Published r oot WebApplicationContext as ServletContext attribute with name [org.springframe work.web.context.WebApplicationContext.ROOT] 00:42:10.438 [pool-2-thread-1] INFO o.s.web.context.ContextLoader - Root WebApp licationContext: initialization completed in 27447 ms 30-Nov-2012 00:42:11 org.apache.coyote.AbstractProtocol start INFO: Starting ProtocolHandler ["http-apr-8080"] 30-Nov-2012 00:42:11 org.apache.coyote.AbstractProtocol start INFO: Starting ProtocolHandler ["ajp-apr-8009"] 30-Nov-2012 00:42:11 org.apache.catalina.startup.Catalina start INFO: Server startup in 31631 ms
以下是jar依赖项:
compile "org.slf4j:jcl-over-slf4j:$slf4jVersion" compile "org.slf4j:slf4j-api:$slf4jVersion" compile "ch.qos.logback:logback-classic:${logbackVersion}" compile "ch.qos.logback:logback-core:${logbackVersion}" compile "ch.qos.logback:logback-access:${logbackVersion}"
我已经解决了这个问题。
正如解释这里说LogbackConfigListener应该在web.xml文件中的第一个听众。
我在Spring的ContextLoaderListener下面编写LogbackConfigListener。该序列与Log4jConfigListener一起使用可能是因为两个侦听器都是Spring框架的一部分。