Add condition to log only if fine level is loggable
Even if FINE level is not loggable String.format() works every time and tries to format string with all the events. Sometimes it causes OutOfMemory exceptions.
This commit is contained in:
@@ -273,7 +273,9 @@ public class Socket extends Emitter {
|
||||
}
|
||||
|
||||
private void onclose(String reason) {
|
||||
logger.fine(String.format("close (%s)", reason));
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine(String.format("close (%s)", reason));
|
||||
}
|
||||
this.connected = false;
|
||||
this.id = null;
|
||||
this.emit(EVENT_DISCONNECT, reason);
|
||||
@@ -327,7 +329,9 @@ public class Socket extends Emitter {
|
||||
|
||||
private void onevent(Packet<JSONArray> packet) {
|
||||
List<Object> args = new ArrayList<Object>(Arrays.asList(toArray(packet.data)));
|
||||
logger.fine(String.format("emitting event %s", args));
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine(String.format("emitting event %s", args));
|
||||
}
|
||||
|
||||
if (packet.id >= 0) {
|
||||
logger.fine("attaching ack callback to event");
|
||||
@@ -354,7 +358,9 @@ public class Socket extends Emitter {
|
||||
public void run() {
|
||||
if (sent[0]) return;
|
||||
sent[0] = true;
|
||||
logger.fine(String.format("sending ack %s", args.length != 0 ? args : null));
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine(String.format("sending ack %s", args.length != 0 ? args : null));
|
||||
}
|
||||
|
||||
JSONArray jsonArgs = new JSONArray();
|
||||
for (Object arg : args) {
|
||||
@@ -375,10 +381,14 @@ public class Socket extends Emitter {
|
||||
private void onack(Packet<JSONArray> packet) {
|
||||
Ack fn = this.acks.remove(packet.id);
|
||||
if (fn != null) {
|
||||
logger.fine(String.format("calling ack %s with %s", packet.id, packet.data));
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine(String.format("calling ack %s with %s", packet.id, packet.data));
|
||||
}
|
||||
fn.call(toArray(packet.data));
|
||||
} else {
|
||||
logger.fine(String.format("bad ack %s", packet.id));
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine(String.format("bad ack %s", packet.id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -404,7 +414,9 @@ public class Socket extends Emitter {
|
||||
}
|
||||
|
||||
private void ondisconnect() {
|
||||
logger.fine(String.format("server disconnect (%s)", this.nsp));
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine(String.format("server disconnect (%s)", this.nsp));
|
||||
}
|
||||
this.destroy();
|
||||
this.onclose("io server disconnect");
|
||||
}
|
||||
@@ -431,7 +443,9 @@ public class Socket extends Emitter {
|
||||
@Override
|
||||
public void run() {
|
||||
if (Socket.this.connected) {
|
||||
logger.fine(String.format("performing disconnect (%s)", Socket.this.nsp));
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine(String.format("performing disconnect (%s)", Socket.this.nsp));
|
||||
}
|
||||
Socket.this.packet(new Packet(Parser.DISCONNECT));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user