使用logback-1.0.13.jar
和 JDK 1.6u34。
我有一个 Java Web 应用程序 (WAR),其中包含以下内容WEB-INF/classes/logback.xml
:
<configuration debug="true" scan="true" scanPeriod="5 minutes">
<appender name="logManager-dbAppender" class="ch.qos.logback.classic.db.DBAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>NEUTRAL</onMismatch>
</filter>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>WARN</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>NEUTRAL</onMismatch>
</filter>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<connectionSource class="ch.qos.logback.core.db.JNDIConnectionSource">
<jndiLocation>java:comp/env/jdbc/dbLogging-local</jndiLocation>
</connectionSource>
</appender>
<root level="ALL">
<appender-ref ref="logManager-dbAppender" />
</root>
</configuration>
以及以下(所有网络应用程序的${TOMCAT_HOME}/conf/context.xml
全局):context.xml
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource
name="jdbc/dbLogging-local"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://my-mysql-server.example.com:3306/my_db"
username="my_user"
password="my_password"
maxActive="20"
/>
</Context>
并在我的运行时类路径中拥有最新的 MySQL/JDBC 驱动程序WEB-INF/lib/mysql-jdbc-5.1.25.jar
)。此外,因为这是一个全局的context.xml
,所以我在${TOMCAT_HOME}
/lib 也有相同的 MySQL/JDBC 驱动程序。
我得到以下堆栈跟踪:
08:54:52,905 |-ERROR in ch.qos.logback.classic.db.DBAppender[logManager-dbAppender] - problem appending event com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'caller_filename' cannot be null
at com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'caller_filename' cannot be null
at at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at at com.mysql.jdbc.Util.getInstance(Util.java:386)
at at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1040)
at at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096)
at at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4028)
at at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490)
at at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
at at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2734)
at at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
at at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458)
at at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2375)
at at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2359)
at at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
at at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
at at ch.qos.logback.classic.db.DBAppender.subAppend(DBAppender.java:105)
at at ch.qos.logback.classic.db.DBAppender.subAppend(DBAppender.java:42)
at at ch.qos.logback.core.db.DBAppenderBase.append(DBAppenderBase.java:108)
at at ch.qos.logback.core.UnsynchronizedAppenderBase.doAppend(UnsynchronizedAppenderBase.java:88)
at at ch.qos.logback.core.spi.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:48)
at at ch.qos.logback.classic.Logger.appendLoopOnAppenders(Logger.java:272)
at at ch.qos.logback.classic.Logger.callAppenders(Logger.java:259)
at at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:441)
at at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:395)
at at ch.qos.logback.classic.Logger.info(Logger.java:599)
at at com.myapp.server.DummyServlet.doGet(Unknown Source)
at at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at at java.lang.Thread.run(Thread.java:662)
关于为什么我得到 MySQL 异常的任何想法?我在 Old Nabble 上发现了类似的未回答问题,我想知道这是否是一个长期存在的错误......?
logging_event.caller_filename
当(根据 Logback DBAppender 的 onw DDL)该列上不允许NULL 时,它似乎正在连接到我的 MySQL 服务器并插入 NULL 。
提前致谢!