From 314204313dbff6c8c6f26fd513fc466542b2c9a2 Mon Sep 17 00:00:00 2001 From: "Juan F. Codagnone" Date: Wed, 6 Jul 2016 12:31:27 -0300 Subject: [PATCH] AsyncLogger: avoid useless concatenations if debug is disabled --- .../java/com/logentries/net/AsyncLogger.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/logentries/net/AsyncLogger.java b/src/main/java/com/logentries/net/AsyncLogger.java index 5676b05..1c38ab3 100644 --- a/src/main/java/com/logentries/net/AsyncLogger.java +++ b/src/main/java/com/logentries/net/AsyncLogger.java @@ -107,7 +107,9 @@ public class AsyncLogger { */ public void setToken( String token) { this.token = token; - dbg( "Setting token to " + token); + if (debug) { + dbg( "Setting token to " + token); + } } /** @@ -420,7 +422,9 @@ public void addLineToQueue(String line) { private void addLineToQueue (String line, int limit) { if (limit == 0) { - dbg("Message longer than " + RECURSION_LIMIT); + if (debug) { + dbg("Message longer than " + RECURSION_LIMIT); + } return; } //// Check credentials only if logs are sent to LE directly. @@ -432,7 +436,9 @@ private void addLineToQueue (String line, int limit) { started = true; } - dbg("Queueing " + line); + if (debug) { + dbg("Queueing " + line); + } // If individual string is too long add it to the queue recursively as sub-strings if (line.length() > LOG_LENGTH_LIMIT) { @@ -553,7 +559,9 @@ void reopenConnection() throws InterruptedException { if (root_delay > MAX_DELAY) root_delay = MAX_DELAY; int wait_for = root_delay + random.nextInt( root_delay); - dbg( "Waiting for " + wait_for + "ms"); + if (debug) { + dbg( "Waiting for " + wait_for + "ms"); + } Thread.sleep( wait_for); } } @@ -666,7 +674,9 @@ public void run() { } catch (InterruptedException e) { // We got interrupted, stop dbg( "Asynchronous socket writer interrupted"); - dbg("Queue had "+queue.size()+" lines left in it"); + if (debug) { + dbg("Queue had "+queue.size()+" lines left in it"); + } } closeConnection();