I wrote this a little while ago: https://github.com/jvz/log4j-jdbc-spring-test
I'm more keen on using the NoSQL appenders for the flexibility in storing the ThreadContext with the messages, however. On 5 August 2014 08:42, Remko Popma <[email protected]> wrote: > > > On Tuesday, August 5, 2014, Matt Sicker <[email protected]> wrote: > >> It's only on startup of the appender, so I don't think it's too big a >> deal. I'm thinking of adding a setting to force enable/disable using batch >> queries. >> > > That's a good idea. This would be a JDBC Appender option? On by default > (if the DB supports it), but users can switch it off if it causes issues > somehow. Sounds good! > > Theoretically this should give very nice performance benefits, but I > haven't used it myself so I can't say. Has anyone ever used this in > practice? > > >> On 5 August 2014 06:40, Gary Gregory <[email protected]> wrote: >> >>> Curious: is there a perf hit in getting the connection metadata? >>> >>> Gary >>> >>> >>> -------- Original message -------- >>> From: [email protected] >>> Date:08/05/2014 00:35 (GMT-05:00) >>> To: [email protected] >>> Subject: svn commit: r1615861 - >>> /logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcDatabaseManager.java >>> >>> >>> Author: mattsicker >>> Date: Tue Aug 5 04:35:41 2014 >>> New Revision: 1615861 >>> >>> URL: http://svn.apache.org/r1615861 >>> Log: >>> Add basic batch update support for JDBC appender. >>> >>> - Part of LOG4J2-734 >>> >>> Modified: >>> >>> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcDatabaseManager.java >>> >>> Modified: >>> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcDatabaseManager.java >>> URL: >>> http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcDatabaseManager.java?rev=1615861&r1=1615860&r2=1615861&view=diff >>> >>> ============================================================================== >>> --- >>> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcDatabaseManager.java >>> (original) >>> +++ >>> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcDatabaseManager.java >>> Tue Aug 5 04:35:41 2014 >>> @@ -18,6 +18,7 @@ package org.apache.logging.log4j.core.ap >>> >>> import java.io.StringReader; >>> import java.sql.Connection; >>> +import java.sql.DatabaseMetaData; >>> import java.sql.PreparedStatement; >>> import java.sql.SQLException; >>> import java.sql.Timestamp; >>> @@ -43,6 +44,7 @@ public final class JdbcDatabaseManager e >>> >>> private Connection connection; >>> private PreparedStatement statement; >>> + private boolean isBatchSupported; >>> >>> private JdbcDatabaseManager(final String name, final int >>> bufferSize, final ConnectionSource connectionSource, >>> final String sqlStatement, final >>> List<Column> columns) { >>> @@ -53,8 +55,11 @@ public final class JdbcDatabaseManager e >>> } >>> >>> @Override >>> - protected void startupInternal() { >>> - // nothing to see here >>> + protected void startupInternal() throws Exception { >>> + this.connection = this.connectionSource.getConnection(); >>> + final DatabaseMetaData metaData = this.connection.getMetaData(); >>> + this.isBatchSupported = metaData.supportsBatchUpdates(); >>> + Closer.closeSilently(this.connection); >>> } >>> >>> @Override >>> @@ -109,7 +114,9 @@ public final class JdbcDatabaseManager e >>> } >>> } >>> >>> - if (this.statement.executeUpdate() == 0) { >>> + if (this.isBatchSupported) { >>> + this.statement.addBatch(); >>> + } else if (this.statement.executeUpdate() == 0) { >>> throw new AppenderLoggingException( >>> "No records inserted in database table for log >>> event in JDBC manager."); >>> } >>> @@ -125,6 +132,9 @@ public final class JdbcDatabaseManager e >>> protected void commitAndClose() { >>> try { >>> if (this.connection != null && !this.connection.isClosed()) >>> { >>> + if (this.isBatchSupported) { >>> + this.statement.executeBatch(); >>> + } >>> this.connection.commit(); >>> } >>> } catch (final SQLException e) { >>> >>> >>> >> >> >> -- >> Matt Sicker <[email protected]> >> > -- Matt Sicker <[email protected]>
