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:
Sergey Davydov
2017-05-28 13:01:18 +03:00
parent 8f8c138a61
commit 229a820bf5
4 changed files with 46 additions and 15 deletions

View File

@@ -77,7 +77,9 @@ public class Parser {
public Encoder() {}
public void encode(Packet obj, Callback callback) {
logger.fine(String.format("encoding packet %s", obj));
if (logger.isLoggable(Level.FINE)) {
logger.fine(String.format("encoding packet %s", obj));
}
if (BINARY_EVENT == obj.type || BINARY_ACK == obj.type) {
encodeAsBinary(obj, callback);
@@ -116,7 +118,9 @@ public class Parser {
str.append(obj.data);
}
logger.fine(String.format("encoded %s as %s", obj, str));
if (logger.isLoggable(Level.FINE)) {
logger.fine(String.format("encoded %s as %s", obj, str));
}
return str.toString();
}
@@ -233,7 +237,9 @@ public class Parser {
}
}
logger.fine(String.format("decoded %s as %s", str, p));
if (logger.isLoggable(Level.FINE)) {
logger.fine(String.format("decoded %s as %s", str, p));
}
return p;
}