2013-06-04 61 views
1

使用logback-1.0.13.jar和JDK 1.6u34。Logback DBAppender具有null caller_filename

我有以下WEB-INF/classes/logback.xml一個Java Web應用程序(WAR):

<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(爲所有Web應用程序的全球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> 

,並且對latest MySQL/JDBC driver我的運行時類路徑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的例外呢?我在老Nabble上發現了this similar unanswered question,我想知道它是否是一個長期存在的bug ...?

當(根據Logback DBAppender的onw DDL)NULL不允許在該列上時,它似乎連接到我的MySQL服務器並插入NULL logging_event.caller_filename

在此先感謝!

回答

0

我用PostgreSQL和logback 1.0.7與slf4j有類似的問題1.6.6 不知何故似乎調用者信息並非「總是」通過什麼導致這個問題,這反過來意味着有關的日誌記錄調用doesn不會對數據庫產生影響(如果logback配置中沒有debug =「true」,那麼您甚至不知道它)。

作爲一個虛擬解決方案,可以放鬆日誌表中的數據庫列約束(在調用者列中不要求「not null」)。在我的情況然而,事實證明它的問題我如何構建記錄器實例代碼:雖然這已引起上述故障

import org.slf4j.Logger; 
import org.slf4j.LoggerFactory; 

Logger log = LoggerFactory.getLogger(My.class); 

這個工作的罰款(即充滿來電者信息)

Logger log = LoggerFactory.getLogger(My.class.getName()); 

我不能解釋它。