log4j数据库日志插入异常解决方案。

时间:2022-07-03 21:43:39
2015-11-18 08:56:08,486 ERROR Unable to write to database [jdbcManager{ description=databaseAppender, bufferSize=0, connectionSource=factory{ public static java.sql.Connection haige.sat.util.ConnectionFactory.getDatabaseConnection() }, tableName=logs, columns=[ { name=date, layout=%d{yyyy-MM-dd HH:mm:ss}, literal=null, timestamp=false }, { name=level, layout=%level, literal=null, timestamp=false }, { name=message, layout=%message, literal=null, timestamp=false } ] }] for appender [databaseAppender]. org.apache.logging.log4j.core.appender.AppenderLoggingException: Failed to commit transaction logging event or flushing buffer.
    at org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.commitAndClose(JdbcDatabaseManager.java:142)
    at org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager.write(AbstractDatabaseManager.java:166)
    at org.apache.logging.log4j.core.appender.db.AbstractDatabaseAppender.append(AbstractDatabaseAppender.java:103)
    at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:97)
    at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:428)
    at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:407)
    at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:365)
    at org.apache.logging.log4j.core.Logger.logMessage(Logger.java:112)
    at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:1336)
    at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1325)
    at org.apache.logging.log4j.spi.AbstractLogger.info(AbstractLogger.java:907)
    at haige.sat.listener.HostInfoChecker.checkMainHostService(HostInfoChecker.java:301)
    at haige.sat.listener.HostInfoChecker.run(HostInfoChecker.java:154)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.BatchUpdateException: Cannot execute statement: impossible to write to binary log since BINLOG_FORMAT = STATEMENT and at least one table uses a storage engine limited to row-based logging. InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.
    at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2055)
    at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1467)
    at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297)
    at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297)
    at org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.commitAndClose(JdbcDatabaseManager.java:137)
    ... 13 more
Caused by: java.sql.SQLException: Cannot execute statement: impossible to write to binary log since BINLOG_FORMAT = STATEMENT and at least one table uses a storage engine limited to row-based logging. InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4237)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2617)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2778)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2825)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2156)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2459)
    at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2007)
    ... 17 more

2015-11-18 08:56:08,488 ERROR An exception occurred processing Appender databaseAppender org.apache.logging.log4j.core.appender.AppenderLoggingException: Failed to commit transaction logging event or flushing buffer.
    at org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.commitAndClose(JdbcDatabaseManager.java:142)
    at org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager.write(AbstractDatabaseManager.java:166)
    at org.apache.logging.log4j.core.appender.db.AbstractDatabaseAppender.append(AbstractDatabaseAppender.java:103)
    at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:97)
    at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:428)
    at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:407)
    at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:365)
    at org.apache.logging.log4j.core.Logger.logMessage(Logger.java:112)
    at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:1336)
    at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1325)
    at org.apache.logging.log4j.spi.AbstractLogger.info(AbstractLogger.java:907)
    at haige.sat.listener.HostInfoChecker.checkMainHostService(HostInfoChecker.java:301)
    at haige.sat.listener.HostInfoChecker.run(HostInfoChecker.java:154)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.BatchUpdateException: Cannot execute statement: impossible to write to binary log since BINLOG_FORMAT = STATEMENT and at least one table uses a storage engine limited to row-based logging. InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.
    at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2055)
    at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1467)
    at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297)
    at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297)
    at org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.commitAndClose(JdbcDatabaseManager.java:137)

    ... 13 more


最近在工作中遇到jetty服务器启动时,数据库日志插入异常,在寻找了许多资料后发现是数据库的插入更新方式BINLOG_FORMAT = STATEMENT造成的,解决方案是在Mysql数据库命令行下 set GLOBAL binlog_format = "Mixed",但是每次重启机器后都要设置,不知道哪位大神有解决方案,分享一下