Skip to content

Commit

Permalink
Change Logging to SLF4J
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Jul 17, 2015
1 parent 5c8f4fe commit 6d1cab7
Show file tree
Hide file tree
Showing 41 changed files with 337 additions and 338 deletions.
13 changes: 12 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<artifactId>mariadb-java-client</artifactId>
<packaging>jar</packaging>
<name>mariadb-java-client</name>
<version>1.2.0</version>
<version>1.2.1-SNAPSHOT</version>
<description>JDBC driver for MariaDB and MySQL</description>
<url>https://mariadb.com/kb/en/mariadb/about-mariadb-connector-j/</url>
<properties>
Expand Down Expand Up @@ -236,6 +236,17 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/org/mariadb/jdbc/Driver.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.mariadb.jdbc.internal.common.QueryException;
import org.mariadb.jdbc.internal.common.Utils;
import org.mariadb.jdbc.internal.mysql.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Proxy;
import java.sql.Connection;
Expand All @@ -62,14 +64,11 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import java.sql.SQLFeatureNotSupportedException;
import java.util.Properties;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.logging.Logger;



public final class Driver implements java.sql.Driver {
/**
* the logger.
*/
private static final Logger log = Logger.getLogger(Driver.class.getName());
private final static Logger log = LoggerFactory.getLogger(Driver.class);

static {
try {
Expand All @@ -90,7 +89,7 @@ public final class Driver implements java.sql.Driver {
*/
public Connection connect(final String url, final Properties props) throws SQLException {

log.finest("Connecting to: " + url);
log.debug("Connecting to: " + url);
try {
JDBCUrl jdbcUrl = JDBCUrl.parse(url, props);
if (jdbcUrl.getHostAddresses() == null) {
Expand Down Expand Up @@ -159,7 +158,7 @@ public boolean jdbcCompliant() {
return false;
}

public Logger getParentLogger() throws SQLFeatureNotSupportedException {
public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException {
// TODO Auto-generated method stub
return null;
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/mariadb/jdbc/MySQLDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.mariadb.jdbc.internal.common.UrlHAMode;
import org.mariadb.jdbc.internal.common.Utils;
import org.mariadb.jdbc.internal.mysql.*;
import org.slf4j.LoggerFactory;

import javax.sql.*;

Expand All @@ -71,7 +72,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS


public class MySQLDataSource implements DataSource, ConnectionPoolDataSource, XADataSource {
private final static Logger log = Logger.getLogger(MySQLDataSource.class.getName());
private final static org.slf4j.Logger log = LoggerFactory.getLogger(MySQLDataSource.class);

private final JDBCUrl jdbcUrl;

Expand Down Expand Up @@ -271,7 +272,7 @@ public Connection getConnection() throws SQLException {
public Connection getConnection(final String username, final String password) throws SQLException {
jdbcUrl.setUsername(username);
jdbcUrl.setPassword(password);
log.finest("connection : " +jdbcUrl.toString());
if (log.isDebugEnabled()) log.debug("connection : " +jdbcUrl.toString());
return getConnection();
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/mariadb/jdbc/MySQLPreparedStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.mariadb.jdbc.internal.common.Utils;
import org.mariadb.jdbc.internal.common.query.*;
import org.mariadb.jdbc.internal.common.query.parameters.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -64,12 +66,10 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;


public class MySQLPreparedStatement extends MySQLStatement implements PreparedStatement {
private final static Logger log = Logger.getLogger(MySQLPreparedStatement.class.getName());
private final static Logger log = LoggerFactory.getLogger(MySQLPreparedStatement.class);
private MySQLParameterizedQuery dQuery;
private String sql;
private boolean useFractionalSeconds;
Expand All @@ -82,8 +82,8 @@ public MySQLPreparedStatement(MySQLConnection connection,
this.sql = sql;
useFractionalSeconds =
connection.getProtocol().getOptions().useFractionalSeconds;
if(log.isLoggable(Level.FINEST)) {
log.finest("Creating prepared statement for " + sql);
if(log.isDebugEnabled()) {
log.debug("Creating prepared statement for " + sql);
}
dQuery = new MySQLParameterizedQuery(Utils.nativeSQL(sql, connection.noBackslashEscapes),
connection.noBackslashEscapes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,6 @@ public enum DefaultOptions {
*/
FAIL_ON_READ_ONLY("failOnReadOnly", Boolean.FALSE, "1.2.0"),

/**
* If autoReconnect is enabled, the initial time to wait between re-connect attempts (in seconds, defaults to 2)
*/
INITIAL_TIMEOUT("initialTimeout", new Integer(2), new Integer(0), Integer.MAX_VALUE, "1.2.0"),

/**
* Number of seconds to issue before falling back to master when failed over (when using multi-host failover).
* Whichever condition is met first, 'queriesBeforeRetryMaster' or 'secondsBeforeRetryMaster' will cause an
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/org/mariadb/jdbc/internal/common/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public class Options {
//HA options
public boolean autoReconnect;
public boolean failOnReadOnly;
public int initialTimeout;
public int secondsBeforeRetryMaster;
public int queriesBeforeRetryMaster;
public int retriesAllDown;
Expand Down Expand Up @@ -132,7 +131,6 @@ public String toString() {
", useOldAliasMetadataBehavior=" + useOldAliasMetadataBehavior +
", autoReconnect=" + autoReconnect +
", failOnReadOnly=" + failOnReadOnly +
", initialTimeout=" + initialTimeout +
", secondsBeforeRetryMaster=" + secondsBeforeRetryMaster +
", queriesBeforeRetryMaster=" + queriesBeforeRetryMaster +
", retriesAllDown=" + retriesAllDown +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package org.mariadb.jdbc.internal.common.packet;
import org.mariadb.jdbc.internal.common.packet.commands.StreamedQueryPacket;
import org.mariadb.jdbc.internal.common.query.MySQLQuery;

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

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;


public class PacketOutputStream extends OutputStream {
private final static Logger log = Logger.getLogger("org.maria.jdbc");
private final static Logger log = LoggerFactory.getLogger(PacketOutputStream.class);

private static final int MAX_PACKET_LENGTH = 0x00ffffff;
private static final int SEQNO_OFFSET = 3;
Expand Down Expand Up @@ -133,10 +132,10 @@ private void internalFlush() throws IOException {
throw new MaxAllowedPacketException("max_allowed_packet exceeded. wrote " + bytesWritten + ", max_allowed_packet = " +maxAllowedPacket, this.seqNo != 0);
}
baseStream.write(byteBuffer, 0, position);
if (log.isLoggable(Level.FINEST)) {
if (log.isTraceEnabled()) {
byte[] tmp = new byte[Math.min(1000, position)];
System.arraycopy(byteBuffer, 0, tmp, 0, Math.min(1000, position));
log.finest(new String(tmp));
log.trace(new String(tmp));
}

position = HEADER_LENGTH;
Expand Down
39 changes: 17 additions & 22 deletions src/main/java/org/mariadb/jdbc/internal/mysql/AuroraProtocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.mariadb.jdbc.internal.common.queryresults.SelectQueryResult;
import org.mariadb.jdbc.internal.mysql.listener.impl.AuroraListener;
import org.mariadb.jdbc.internal.mysql.listener.tools.SearchFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.*;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.logging.Level;
import java.util.logging.Logger;

public class AuroraProtocol extends MastersSlavesProtocol {
private final static Logger log = Logger.getLogger(AuroraProtocol.class.getName());
private final static Logger log = LoggerFactory.getLogger(AuroraProtocol.class);

public AuroraProtocol(final JDBCUrl url, final ReentrantReadWriteLock lock) {
super(url, lock);
Expand Down Expand Up @@ -97,7 +97,7 @@ public boolean checkIfMaster() throws QueryException {
return this.masterConnection;

} catch (IOException ioe) {
log.log(Level.FINEST, "exception during checking if master", ioe);
log.trace("exception during checking if master", ioe);
throw new QueryException("could not check the 'innodb_read_only' variable status on " + this.getHostAddress() +
" : " + ioe.getMessage(), -1, SQLExceptionMapper.SQLStates.CONNECTION_EXCEPTION.getSqlState(), ioe);
} finally {
Expand All @@ -107,16 +107,16 @@ public boolean checkIfMaster() throws QueryException {


public static void searchProbableMaster(AuroraListener listener, HostAddress probableMaster, Map<HostAddress, Long> blacklist, SearchFilter searchFilter) throws QueryException {
if (log.isLoggable(Level.FINE)) {
log.fine("searching for master:" + searchFilter.isSearchForMaster() + " replica:" + searchFilter.isSearchForSlave() + " address:" + probableMaster + " blacklist:" + blacklist.keySet());
if (log.isDebugEnabled()) {
log.debug("searching for master:" + searchFilter.isSearchForMaster() + " replica:" + searchFilter.isSearchForSlave() + " address:" + probableMaster + " blacklist:" + blacklist.keySet());
}
AuroraProtocol protocol = getNewProtocol(listener.getProxy(), listener.getJdbcUrl());
try {

protocol.setHostAddress(probableMaster);
if (log.isLoggable(Level.FINE)) log.fine("trying to connect to " + protocol.getHostAddress());
if (log.isTraceEnabled()) log.trace("trying to connect to " + protocol.getHostAddress());
protocol.connect();
if (log.isLoggable(Level.FINE)) log.fine("connected to " + protocol.getHostAddress());
if (log.isTraceEnabled()) log.trace("connected to " + protocol.getHostAddress());

if (searchFilter.isSearchForMaster() && protocol.isMasterConnection()) {
searchFilter.setSearchForMaster(false);
Expand All @@ -127,16 +127,16 @@ public static void searchProbableMaster(AuroraListener listener, HostAddress pro
protocol.setMustBeMasterConnection(false);
listener.foundActiveSecondary(protocol);
} else {
if (log.isLoggable(Level.FINE))
log.fine("close connection because unused : " + protocol.getHostAddress());
if (log.isDebugEnabled())
log.debug("close connection because unused : " + protocol.getHostAddress());
protocol.close();
protocol = getNewProtocol(listener.getProxy(), listener.getJdbcUrl());
}

} catch (QueryException e) {
blacklist.put(protocol.getHostAddress(), System.currentTimeMillis());
if (log.isLoggable(Level.FINE))
log.fine("Could not connect to " + protocol.currentHost + " searching for master : " + searchFilter.isSearchForMaster() + " for replica :" + searchFilter.isSearchForSlave() + " error:" + e.getMessage());
if (log.isDebugEnabled())
log.debug("Could not connect to " + protocol.currentHost + " searching for master : " + searchFilter.isSearchForMaster() + " for replica :" + searchFilter.isSearchForSlave() + " error:" + e.getMessage());
}
}

Expand All @@ -150,8 +150,8 @@ public static void searchProbableMaster(AuroraListener listener, HostAddress pro
* @throws QueryException if not found
*/
public static void loop(AuroraListener listener, final List<HostAddress> addresses, Map<HostAddress, Long> blacklist, SearchFilter searchFilter) throws QueryException {
if (log.isLoggable(Level.FINE)) {
log.fine("searching for master:" + searchFilter.isSearchForMaster() + " replica:" + searchFilter.isSearchForSlave() + " addresses:" + addresses );
if (log.isDebugEnabled()) {
log.debug("searching for master:" + searchFilter.isSearchForMaster() + " replica:" + searchFilter.isSearchForSlave() + " addresses:" + addresses);
}

AuroraProtocol protocol;
Expand All @@ -169,25 +169,20 @@ public static void loop(AuroraListener listener, final List<HostAddress> address
protocol.setHostAddress(loopAddresses.get(0));
loopAddresses.remove(0);

if (log.isLoggable(Level.FINE)) log.fine("trying to connect to " + protocol.getHostAddress());
if (log.isDebugEnabled()) log.debug("trying to connect to " + protocol.getHostAddress());
protocol.connect();
blacklist.remove(protocol.getHostAddress());
if (log.isLoggable(Level.FINE)) log.fine("connected to " + (protocol.isMasterConnection()?"primary ":"replica ") + protocol.getHostAddress());
if (log.isDebugEnabled()) log.debug("connected to " + (protocol.isMasterConnection()?"primary ":"replica ") + protocol.getHostAddress());

if (searchFilter.isSearchForMaster() && protocol.isMasterConnection()) {
log.finest("locks -0 : "+protocol.getProxy().lock.getReadHoldCount() + " "+protocol.getProxy().lock.getWriteHoldCount());
if (foundMaster(listener, protocol, searchFilter)) return;
log.finest("locks -1: "+protocol.getProxy().lock.getReadHoldCount() + " "+protocol.getProxy().lock.getWriteHoldCount());
} else if (searchFilter.isSearchForSlave() && !protocol.isMasterConnection()) {
log.finest("locks -2: "+protocol.getProxy().lock.getReadHoldCount() + " "+protocol.getProxy().lock.getWriteHoldCount());
if (foundSecondary(listener, protocol, searchFilter)) return;
log.finest("locks -3: "+protocol.getProxy().lock.getReadHoldCount() + " "+protocol.getProxy().lock.getWriteHoldCount());

HostAddress probableMasterHost = listener.searchByStartName(protocol, listener.getJdbcUrl().getHostAddresses());
if (probableMasterHost != null) {
loopAddresses.remove(probableMasterHost);
AuroraProtocol.searchProbableMaster(listener, probableMasterHost, blacklist, searchFilter);
log.finest("locks -4: "+protocol.getProxy().lock.getReadHoldCount() + " "+protocol.getProxy().lock.getWriteHoldCount());
if (!searchFilter.isSearchForMaster()) return;
}
} else {
Expand All @@ -196,7 +191,7 @@ public static void loop(AuroraListener listener, final List<HostAddress> address
} catch (QueryException e) {
lastQueryException = e;
blacklist.put(protocol.getHostAddress(), System.currentTimeMillis());
if (log.isLoggable(Level.FINE)) log.fine("Could not connect to " + protocol.getHostAddress() + " searching: " + searchFilter + " error: " + e.getMessage());
if (log.isDebugEnabled()) log.debug("Could not connect to " + protocol.getHostAddress() + " searching: " + searchFilter + " error: " + e.getMessage());
}

if (!searchFilter.isSearchForMaster() && !searchFilter.isSearchForSlave()) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,18 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.mariadb.jdbc.internal.SQLExceptionMapper;
import org.mariadb.jdbc.internal.common.QueryException;
import org.mariadb.jdbc.internal.mysql.listener.Listener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.SQLException;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.logging.Logger;


public class FailoverProxy implements InvocationHandler {
private final static Logger log = Logger.getLogger(FailoverProxy.class.getName());
private final static Logger log = LoggerFactory.getLogger(FailoverProxy.class);

public final static String METHOD_IS_EXPLICIT_CLOSED = "isExplicitClosed";
public final static String METHOD_GET_OPTIONS = "getOptions";
Expand Down
Loading

0 comments on commit 6d1cab7

Please sign in to comment.