Skip to content
This repository was archived by the owner on Dec 12, 2021. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/main/java/com/logentries/net/AsyncLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/**
Expand Down Expand Up @@ -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.
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -666,7 +674,9 @@ public void run() {
} catch (InterruptedException e) {
// We got interrupted, stop
dbg( "Asynchronous socket writer interrupted");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could add this call under the if as well... once debug is disabled there is no point in calling it. ;)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dbg() will check if debug is enabled, so it wont be a gain (the gain is in avoiding the string concatenation).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I knew it. But, even though you will reduce one if test. ;)

dbg("Queue had "+queue.size()+" lines left in it");
if (debug) {
dbg("Queue had "+queue.size()+" lines left in it");
}
}

closeConnection();
Expand Down