Skip to content

Commit

Permalink
ARTEMIS-2051 add trace logging for JDBC
Browse files Browse the repository at this point in the history
Activate by enabling TRACE logging for:
org.apache.activemq.artemis.jdbc.store.drivers.AbstractJDBCDriver
This doesn't log *all* JDBC operations, just those that are used by the
JDBC store.
  • Loading branch information
jbertram authored and clebertsuconic committed Aug 28, 2018
1 parent a8dad35 commit 41b094d
Show file tree
Hide file tree
Showing 6 changed files with 2,625 additions and 2 deletions.
Expand Up @@ -30,6 +30,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.activemq.artemis.jdbc.store.logging.LoggingConnection;
import org.apache.activemq.artemis.jdbc.store.sql.SQLProvider;
import org.apache.activemq.artemis.journal.ActiveMQJournalLogger;
import org.jboss.logging.Logger;
Expand Down Expand Up @@ -85,7 +86,11 @@ public void start() throws SQLException {
}

public AbstractJDBCDriver(Connection connection, SQLProvider sqlProvider) {
this.connection = connection;
if (logger.isTraceEnabled() && !(connection instanceof LoggingConnection)) {
this.connection = new LoggingConnection(connection, logger);
} else {
this.connection = connection;
}
this.sqlProvider = sqlProvider;
this.networkTimeoutExecutor = null;
this.networkTimeoutMillis = -1;
Expand Down Expand Up @@ -118,6 +123,11 @@ private void connect() throws SQLException {
if (dataSource != null) {
try {
connection = dataSource.getConnection();

if (logger.isTraceEnabled() && !(connection instanceof LoggingConnection)) {
this.connection = new LoggingConnection(connection, logger);
}

} catch (SQLException e) {
logger.error(JDBCUtils.appendSQLExceptionDetails(new StringBuilder(), e));
throw e;
Expand All @@ -132,6 +142,11 @@ private void connect() throws SQLException {
}
final Driver dbDriver = getDriver(jdbcDriverClass);
connection = dbDriver.connect(jdbcConnectionUrl, new Properties());

if (logger.isTraceEnabled() && !(connection instanceof LoggingConnection)) {
this.connection = new LoggingConnection(connection, logger);
}

if (connection == null) {
throw new IllegalStateException("the driver: " + jdbcDriverClass + " isn't able to connect to the requested url: " + jdbcConnectionUrl);
}
Expand Down Expand Up @@ -293,7 +308,11 @@ public Connection getConnection() {

public final void setConnection(Connection connection) {
if (this.connection == null) {
this.connection = connection;
if (logger.isTraceEnabled() && !(connection instanceof LoggingConnection)) {
this.connection = new LoggingConnection(connection, logger);
} else {
this.connection = connection;
}
}
}

Expand Down

0 comments on commit 41b094d

Please sign in to comment.