项目开始用slf4j+log4j,没有问题,配置好后一把过。后来想改成slf4j+logback,在网上搜都需要什么依赖以及配置文件后,按照网上的弄了之后,各种报错。一步步解决,弄完这个又报哪个错的,第一次使用不知道咋整。现在又报这个错,都不知道咋整了,大神给看看。
十月 19, 2018 11:08:39 上午 org.apache.catalina.core.AprLifecycleListener init
信息: Loaded APR based Apache Tomcat Native library 1.1.33 using APR version 1.5.1.
十月 19, 2018 11:08:39 上午 org.apache.catalina.core.AprLifecycleListener init
信息: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
十月 19, 2018 11:08:39 上午 org.apache.tomcat.util.digester.SetPropertiesRule begin
警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:eroly' did not find a matching property.
十月 19, 2018 11:08:40 上午 org.apache.catalina.core.AprLifecycleListener initializeSSL
信息: OpenSSL successfully initialized (OpenSSL 1.0.1m 19 Mar 2015)
十月 19, 2018 11:08:41 上午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["http-apr-80"]
十月 19, 2018 11:08:41 上午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["ajp-apr-8009"]
十月 19, 2018 11:08:41 上午 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 2623 ms
十月 19, 2018 11:08:41 上午 org.apache.catalina.core.StandardService startInternal
信息: Starting service Catalina
十月 19, 2018 11:08:41 上午 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet Engine: Apache Tomcat/7.0.52
十月 19, 2018 11:08:42 上午 org.apache.catalina.util.SessionIdGenerator createSecureRandom
信息: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [523] milliseconds.
十月 19, 2018 11:08:42 上午 org.apache.catalina.loader.WebappClassLoader validateJarFile
信息: validateJarFile(D:\e4.5.2_workspaces\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\eroly\WEB-INF\lib\jsp-api-2.1.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/el/Expression.class
十月 19, 2018 11:08:43 上午 org.apache.catalina.loader.WebappClassLoader validateJarFile
信息: validateJarFile(D:\e4.5.2_workspaces\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\eroly\WEB-INF\lib\servlet-api-2.5.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class
十月 19, 2018 11:08:49 上午 org.apache.catalina.core.ApplicationContext log
信息: No Spring WebApplicationInitializer types detected on classpath
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
十月 19, 2018 11:08:49 上午 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext
log4j:WARN No appenders could be found for logger (com.alibaba.druid.pool.DruidAbstractDataSource).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
十月 19, 2018 11:08:56 上午 org.apache.catalina.core.ApplicationContext log
信息: Set web app root system property: 'webapp.root' = [D:\e4.5.2_workspaces\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\eroly\]
十月 19, 2018 11:08:56 上午 org.apache.catalina.core.ApplicationContext log
信息: Initializing Logback from [classpath:logback.xml]
十月 19, 2018 11:08:56 上午 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class ch.qos.logback.ext.spring.web.LogbackConfigListener
java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
at ch.qos.logback.ext.spring.LogbackConfigurer.initLogging(Unknown Source)
at ch.qos.logback.ext.spring.web.WebLogbackConfigurer.initLogging(Unknown Source)
at ch.qos.logback.ext.spring.web.LogbackConfigListener.contextInitialized(Unknown Source)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: org.slf4j.impl.StaticLoggerBinder
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1718)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1569)
... 12 more
十月 19, 2018 11:08:56 上午 org.apache.catalina.core.StandardContext startInternal
严重: Error listenerStart
十月 19, 2018 11:08:56 上午 org.apache.catalina.core.StandardContext startInternal
严重: Context [/eroly] startup failed due to previous errors
十月 19, 2018 11:08:56 上午 org.apache.catalina.core.ApplicationContext log
信息: Shutting down Logback
十月 19, 2018 11:08:56 上午 org.apache.catalina.core.StandardContext listenerStop
严重: Exception sending context destroyed event to listener instance of class ch.qos.logback.ext.spring.web.LogbackConfigListener
java.lang.NoClassDefFoundError: ch/qos/logback/classic/util/ContextSelectorStaticBinder
at ch.qos.logback.ext.spring.LogbackConfigurer.shutdownLogging(Unknown Source)
at ch.qos.logback.ext.spring.web.WebLogbackConfigurer.shutdownLogging(Unknown Source)
at ch.qos.logback.ext.spring.web.LogbackConfigListener.contextDestroyed(Unknown Source)
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:5014)
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5659)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: ch.qos.logback.classic.util.ContextSelectorStaticBinder
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1718)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1569)
... 13 more
十月 19, 2018 11:08:56 上午 org.apache.catalina.core.ApplicationContext log
信息: Closing Spring root WebApplicationContext
十月 19, 2018 11:08:56 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
严重: The web application [/eroly] registered the JDBC driver [com.alibaba.druid.proxy.DruidDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
十月 19, 2018 11:08:56 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
严重: The web application [/eroly] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
十月 19, 2018 11:08:56 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/eroly] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak.
十月 19, 2018 11:08:57 上午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-apr-80"]
十月 19, 2018 11:08:57 上午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["ajp-apr-8009"]
十月 19, 2018 11:08:57 上午 org.apache.catalina.startup.Catalina start
信息: Server startup in 15861 ms
pom文件依赖:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.22</version>
</dependency>
<!-- 这个是桥接包,将已经使用commons-logging记录日志又没法改变(spring默认使用的就是commons-logging)的jar包的日志桥接到slf4 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.22</version>
</dependency>
<!-- logback -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.1.11</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-access</artifactId>
<version>1.1.11</version>
</dependency>
<!-- 具体的日志实现,真正记录日志的jar -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.11</version>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
<scope>provided</scope>
</dependency>
<!-- 为了将logback和spring集成而使用的包,如果不用这个包也可以记录日志,但会有个问题 -->
<dependency>
<groupId>org.logback-extensions</groupId>
<artifactId>logback-ext-spring</artifactId>
<version>0.1.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--debug="true" : 打印logback内部状态(默认当logback运行出错时才会打印内部状态 ),配置该属性后打印条件如下(同时满足):
1、找到配置文件 2、配置文件是一个格式正确的xml文件 也可编程实现打印内部状态,例如: LoggerContext lc = (LoggerContext)
LoggerFactory.getILoggerFactory(); StatusPrinter.print(lc); -->
<!-- scan="true" : 自动扫描该配置文件,若有修改则重新加载该配置文件 -->
<!-- scanPeriod="30 seconds" : 配置自动扫面时间间隔(单位可以是:milliseconds, seconds, minutes
or hours,默认为:milliseconds), 默认为1分钟,scan="true"时该配置才会生效 -->
<configuration debug="false" scan="true" scanPeriod="30 seconds"
packagingData="true">
<!-- 设置 logger context 名称,一旦设置不可改变,默认为default -->
<contextName>eroly</contextName>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>
%d{HH🇲🇲ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>
<appender name="FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>D:/mylog/my_log.log</file>
<!-- 文件滚动策略根据%d{patter}中的“patter”而定,此处为每天产生一个文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 归档文件名“.zip或.gz结尾”,表示归档文件自动压缩 -->
<FileNamePattern>D:/mylog/my_log%d{yyyyMMdd}.%i.log</FileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100KB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<charset>UTF-8</charset>
<pattern>
%d{HH🇲🇲ss.SSS}[%-5level][%thread]%logger{36} - %msg%n
</pattern>
</encoder>
</appender>
<!-- 日志级别若没显示定义,则继承最近的父logger(该logger需显示定义level,直到rootLogger)的日志级别 -->
<!-- logger的appender默认具有累加性(默认日志输出到当前logger的appender和所有祖先logger的appender中),可通过配置
“additivity”属性修改默认行为 -->
<logger name="com.yinz" level="debug" additivity="false">
<appender-ref ref="FILE" />
</logger>
<!-- 至多只能配置一个root -->
<root level="debug">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
</configuration>
web.xml
<context-param>
<param-name>logbackConfigLocation</param-name>
<param-value>classpath:logback.xml</param-value>
</context-param>
<listener>
<listener-class>ch.qos.logback.ext.spring.web.LogbackConfigListener</listener-class>
</listener>
jar包图:
console中的java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder,这个好像是slf4j-log4j12的文件,不知道怎么会找这个
<p>把logback-classic依赖的<scope>provided</scope>删掉,然后就好了。查资料发现如下:<br>
“因为provided意味着打包的时候可以不用打包进去,别的容器会提供。配置provide的被依赖项目会参与编译,测试,运行等周期,同compile,但是在打包阶段做了exclude的动作。”
感觉是运行在Tomcat里时没有把jar加进去,删除掉默认是compile,compile会在打包时加进去,而compile不会,就是这个导致的把。
最后把
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.11</version>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
<scope>provided</scope>
</dependency>
改为
<dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.1.11</version> </dependency>
最后把
logback-core和logback-access也删除了,启动也正常运行。 也是这个原因导致的吧,加的那个scope导致没有把logback-classic打到包里
<p>jar包冲突了</p>
应该找logback的实现吧
怎么冲突了,哪部分
<p>应该是jar冲突,可以在lib下查看下</p>
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。