Skip to content
Permalink
Browse files

fix: add isLoggable around parameterized logger (#752)

Enclose Logger with isLoggable in multi-parameter cases.
  • Loading branch information
jorsol authored and vlsi committed Feb 18, 2017
1 parent b355327 commit 8b50cfe58c47d19adc0c241488a24037f4a4416f
@@ -147,7 +147,9 @@ public void sendQueryCancel() throws SQLException {

// Now we need to construct and send a cancel packet
try {
LOGGER.log(Level.FINEST, " FE=> CancelRequest(pid={0},ckey={1})", new Object[]{cancelPid, cancelKey});
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, " FE=> CancelRequest(pid={0},ckey={1})", new Object[]{cancelPid, cancelKey});
}

cancelStream =
new PGStream(pgStream.getSocketFactory(), pgStream.getHostSpec(), cancelSignalTimeout);
@@ -573,7 +573,9 @@ private void doAuthentication(PGStream pgStream, String host, String user, Prope
}
}

LOGGER.log(Level.FINE, "Using SSPI: {0}, gsslib={1} and SSPI support detected", new Object[]{useSSPI, gsslib});
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Using SSPI: {0}, gsslib={1} and SSPI support detected", new Object[]{useSSPI, gsslib});
}
}

if (useSSPI) {
@@ -261,8 +261,10 @@ private int updateQueryMode(int flags) {
public synchronized void execute(Query query, ParameterList parameters, ResultHandler handler,
int maxRows, int fetchSize, int flags) throws SQLException {
waitOnLock();
LOGGER.log(Level.FINEST, " simple execute, handler={0}, maxRows={1}, fetchSize={2}, flags={3}",
new Object[]{handler, maxRows, fetchSize, flags});
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, " simple execute, handler={0}, maxRows={1}, fetchSize={2}, flags={3}",
new Object[]{handler, maxRows, fetchSize, flags});
}

if (parameters == null) {
parameters = SimpleQuery.NO_PARAMETERS;
@@ -419,8 +421,10 @@ private void rollbackIfRequired(boolean autosave, SQLException e) throws SQLExce
public synchronized void execute(Query[] queries, ParameterList[] parameterLists,
BatchResultHandler batchHandler, int maxRows, int fetchSize, int flags) throws SQLException {
waitOnLock();
LOGGER.log(Level.FINEST, " batch execute {0} queries, handler={1}, maxRows={2}, fetchSize={3}, flags={4}",
new Object[]{queries.length, batchHandler, maxRows, fetchSize, flags});
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, " batch execute {0} queries, handler={1}, maxRows={2}, fetchSize={3}, flags={4}",
new Object[]{queries.length, batchHandler, maxRows, fetchSize, flags});
}

flags = updateQueryMode(flags);

@@ -598,7 +602,9 @@ public ParameterList createFastpathParameters(int count) {

private void sendFastpathCall(int fnid, SimpleParameterList params)
throws SQLException, IOException {
LOGGER.log(Level.FINEST, " FE=> FunctionCall({0}, {1} params)", new Object[]{fnid, params.getParameterCount()});
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, " FE=> FunctionCall({0}, {1} params)", new Object[]{fnid, params.getParameterCount()});
}

//
// Total size = 4 (length)
@@ -1124,7 +1130,10 @@ CopyOperationImpl processCopyResults(CopyOperationImpl op, boolean block)
int l_len = pgStream.receiveInteger4();
String name = pgStream.receiveString();
String value = pgStream.receiveString();
LOGGER.log(Level.FINEST, " <=BE ParameterStatus({0} = {1})", new Object[]{name, value});

if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, " <=BE ParameterStatus({0} = {1})", new Object[]{name, value});
}

if (name.equals("client_encoding") && !value.equalsIgnoreCase("UTF8")
&& !allowEncodingChanges) {
@@ -1410,8 +1419,7 @@ private void sendBind(SimpleQuery query, SimpleParameterList params, Portal port
byte[] encodedPortalName = (portal == null ? null : portal.getEncodedPortalName());

if (LOGGER.isLoggable(Level.FINEST)) {
StringBuilder sbuf =
new StringBuilder(" FE=> Bind(stmt=" + statementName + ",portal=" + portal);
StringBuilder sbuf = new StringBuilder(" FE=> Bind(stmt=" + statementName + ",portal=" + portal);
for (int i = 1; i <= params.getParameterCount(); ++i) {
sbuf.append(",$").append(i).append("=<")
.append(params.toString(i,true))
@@ -1589,8 +1597,9 @@ private void sendExecute(SimpleQuery query, Portal portal, int limit) throws IOE
//
// Send Execute.
//

LOGGER.log(Level.FINEST, " FE=> Execute(portal={0},limit={1})", new Object[]{portal, limit});
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, " FE=> Execute(portal={0},limit={1})", new Object[]{portal, limit});
}

byte[] encodedPortalName = (portal == null ? null : portal.getEncodedPortalName());
int encodedSize = (encodedPortalName == null ? 0 : encodedPortalName.length);
@@ -2120,8 +2129,10 @@ protected void processResults(ResultHandler handler, int flags) throws IOExcepti
// Technically speaking, the error is unexpected, thus we invalidate other
// server-prepared statements just in case.
deallocateEpoch++;
LOGGER.log(Level.FINEST, " FE: received {0}, will invalidate statements. deallocateEpoch is now {1}",
new Object[]{error.getSQLState(), deallocateEpoch});
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, " FE: received {0}, will invalidate statements. deallocateEpoch is now {1}",
new Object[]{error.getSQLState(), deallocateEpoch});
}
}
// keep processing
break;
@@ -2151,7 +2162,10 @@ protected void processResults(ResultHandler handler, int flags) throws IOExcepti
int l_len = pgStream.receiveInteger4();
String name = pgStream.receiveString();
String value = pgStream.receiveString();
LOGGER.log(Level.FINEST, " <=BE ParameterStatus({0} = {1})", new Object[]{name, value});

if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, " <=BE ParameterStatus({0} = {1})", new Object[]{name, value});
}

if (name.equals("client_encoding") && !value.equalsIgnoreCase("UTF8")
&& !allowEncodingChanges) {
@@ -2376,7 +2390,9 @@ private void receiveAsyncNotify() throws IOException {
String param = pgStream.receiveString();
addNotification(new org.postgresql.core.Notification(msg, pid, param));

LOGGER.log(Level.FINEST, " <=BE AsyncNotify({0},{1},{2})", new Object[]{pid, msg, param});
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, " <=BE AsyncNotify({0},{1},{2})", new Object[]{pid, msg, param});
}
}

private SQLException receiveErrorResponse() throws IOException {
@@ -2506,7 +2522,9 @@ public void readStartupMessages() throws IOException, SQLException {
int pid = pgStream.receiveInteger4();
int ckey = pgStream.receiveInteger4();

LOGGER.log(Level.FINEST, " <=BE BackendKeyData(pid={0},ckey={1})", new Object[]{pid, ckey});
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, " <=BE BackendKeyData(pid={0},ckey={1})", new Object[]{pid, ckey});
}

setBackendKeyData(pid, ckey);
break;
@@ -2526,7 +2544,9 @@ public void readStartupMessages() throws IOException, SQLException {
String name = pgStream.receiveString();
String value = pgStream.receiveString();

LOGGER.log(Level.FINEST, " <=BE ParameterStatus({0} = {1})", new Object[]{name, value});
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, " <=BE ParameterStatus({0} = {1})", new Object[]{name, value});
}

if ("server_version_num".equals(name)) {
setServerVersionNum(Integer.parseInt(value));
@@ -186,8 +186,10 @@ private void updateStatusInternal(
long systemClock = TimeUnit.MICROSECONDS.convert((now - POSTGRES_EPOCH_2000_01_01),
TimeUnit.MICROSECONDS);

LOGGER.log(Level.FINEST, " FE=> StandbyStatusUpdate(received: {0}, flushed: {1}, applied: {2}, clock: {3})",
new Object[]{received.asString(), flushed.asString(), applied.asString(), new Date(now)});
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, " FE=> StandbyStatusUpdate(received: {0}, flushed: {1}, applied: {2}, clock: {3})",
new Object[]{received.asString(), flushed.asString(), applied.asString(), new Date(now)});
}

byteBuffer.put((byte) 'r');
byteBuffer.putLong(received.asLong());
@@ -230,8 +232,10 @@ private ByteBuffer processXLogData(ByteBuffer buffer) {
int payloadSize = buffer.limit() - buffer.position();
lastReceiveLSN = LogSequenceNumber.valueOf(startLsn + payloadSize);

LOGGER.log(Level.FINEST, " <=BE XLogData(currWal: {0}, lastServerWal: {1}, clock: {2})",
new Object[]{lastReceiveLSN.asString(), lastServerLSN.asString(), systemClock});
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, " <=BE XLogData(currWal: {0}, lastServerWal: {1}, clock: {2})",
new Object[]{lastReceiveLSN.asString(), lastServerLSN.asString(), systemClock});
}

return buffer.slice();
}
@@ -77,7 +77,9 @@ public Connection getConnection() throws SQLException {
public Connection getConnection(String user, String password) throws SQLException {
try {
Connection con = DriverManager.getConnection(getUrl(), user, password);
LOGGER.log(Level.FINE, "Created a {0} for {1} at {2}", new Object[]{getDescription(), user, getUrl()});
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Created a {0} for {1} at {2}", new Object[]{getDescription(), user, getUrl()});
}
return con;
} catch (SQLException e) {
LOGGER.log(Level.SEVERE, "Failed to create a {0} for {1} at {2}: {3}",
@@ -97,7 +97,9 @@ private static PSQLException cannotCoerceException(final String fromType) {
}

private static PSQLException cannotCoerceException(final String fromType, final String value) {
LOGGER.log(Level.FINE, "Cannot cast type {0} to boolean: \"{1}\"", new Object[]{fromType, value});
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Cannot cast type {0} to boolean: \"{1}\"", new Object[]{fromType, value});
}
return new PSQLException(GT.tr("Cannot cast type {0} to boolean: \"{1}\"", fromType, value),
PSQLState.CANNOT_COERCE);
}
@@ -548,7 +548,10 @@ public Object getObject(String type, String value, byte[] byteValue) throws SQLE

PGobject obj = null;

LOGGER.log(Level.FINEST, "Constructing object from type={0} value=<{1}>", new Object[]{type, value});
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, "Constructing object from type={0} value=<{1}>", new Object[]{type, value});
}

try {
Class<? extends PGobject> klass = _typeCache.getPGobject(type);

@@ -1344,7 +1347,9 @@ public void setClientInfo(String name, String value) throws SQLClientInfoExcepti
GT.tr("Failed to set ClientInfo property: {0}", "ApplicationName"), sqle.getSQLState(),
failures, sqle);
}
LOGGER.log(Level.FINE, " setClientInfo = {0} {1}", new Object[]{name, value});
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, " setClientInfo = {0} {1}", new Object[]{name, value});
}
_clientInfo.put(name, value);
return;
}
@@ -82,7 +82,9 @@
private boolean localAutoCommitMode = true;

private void debug(String s) {
LOGGER.log(Level.FINEST, "XAResource {0}: {1}", new Object[]{Integer.toHexString(this.hashCode()), s});
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, "XAResource {0}: {1}", new Object[]{Integer.toHexString(this.hashCode()), s});
}
}

public PGXAConnection(BaseConnection conn) throws SQLException {
@@ -179,7 +181,7 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
* Postconditions: 1. Connection is associated with the transaction
*/
public void start(Xid xid, int flags) throws XAException {
if (LOGGER.isLoggable(Level.FINER)) {
if (LOGGER.isLoggable(Level.FINEST)) {
debug("starting transaction xid = " + xid);
}

@@ -247,7 +249,7 @@ public void start(Xid xid, int flags) throws XAException {
* Postconditions: 1. connection is disassociated from the transaction.
*/
public void end(Xid xid, int flags) throws XAException {
if (LOGGER.isLoggable(Level.FINER)) {
if (LOGGER.isLoggable(Level.FINEST)) {
debug("ending transaction xid = " + xid);
}

@@ -287,7 +289,7 @@ public void end(Xid xid, int flags) throws XAException {
* Postconditions: 1. Transaction is prepared
*/
public int prepare(Xid xid) throws XAException {
if (LOGGER.isLoggable(Level.FINER)) {
if (LOGGER.isLoggable(Level.FINEST)) {
debug("preparing transaction xid = " + xid);
}

@@ -382,7 +384,7 @@ public int prepare(Xid xid) throws XAException {
* Postconditions: 1. Transaction is rolled back and disassociated from connection
*/
public void rollback(Xid xid) throws XAException {
if (LOGGER.isLoggable(Level.FINER)) {
if (LOGGER.isLoggable(Level.FINEST)) {
debug("rolling back xid = " + xid);
}

@@ -416,7 +418,7 @@ public void rollback(Xid xid) throws XAException {
}

public void commit(Xid xid, boolean onePhase) throws XAException {
if (LOGGER.isLoggable(Level.FINER)) {
if (LOGGER.isLoggable(Level.FINEST)) {
debug("committing xid = " + xid + (onePhase ? " (one phase) " : " (two phase)"));
}

0 comments on commit 8b50cfe

Please sign in to comment.
You can’t perform that action at this time.