-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated to Timber.Tree #3
Open
varshneyjayant
wants to merge
2
commits into
loggly:master
Choose a base branch
from
varshneyjayant:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,13 +24,17 @@ | |
/** | ||
* A <a href="https://github.com/JakeWharton/timber">Timber</a> tree that posts | ||
* log messages to <a href="http://loggly.com">Loggly</a> | ||
* | ||
* @author [email protected] | ||
*/ | ||
public class LogglyTree extends Timber.HollowTree implements Timber.TaggedTree { | ||
public class LogglyTree extends Timber.Tree { | ||
|
||
private final LogglyClient loggly; | ||
private LogglyClient.Callback handler; | ||
private String appName; | ||
private String[] LEVEL = { | ||
"DEBUG", "INFO", "WARN", "ERROR" | ||
}; | ||
private final int DEBUG = 0, INFO = 1, WARN = 2, ERROR = 3; | ||
|
||
/** Log severity level */ | ||
private enum Level { | ||
|
@@ -48,10 +52,44 @@ private enum Level { | |
public LogglyTree(String token) { | ||
loggly = new LogglyClient(token); | ||
|
||
// Setup an async callback | ||
// TODO: handle failed messages with N retries | ||
handler = new LogglyClient.Callback() { | ||
@Override | ||
public void success() { | ||
|
||
} | ||
|
||
@Override | ||
public void failure(String error) { | ||
System.err.println("LogglyTree failed: " + error); | ||
|
||
} | ||
}; | ||
} | ||
|
||
public LogglyTree(String token, String tag) { | ||
loggly = new LogglyClient(token, tag); | ||
// Setup an async callback | ||
// TODO: handle failed messages with N retries | ||
handler = new LogglyClient.Callback() {@Override | ||
public void success() { | ||
// XXX: Handle success | ||
} | ||
|
||
@Override | ||
public void failure(String error) { | ||
System.err.println("LogglyTree failed: " + error); | ||
} | ||
}; | ||
|
||
} | ||
|
||
public LogglyTree(String token, String tag, String appName) { | ||
loggly = new LogglyClient(token, tag); | ||
this.appName = appName; | ||
// Setup an async callback | ||
// TODO: handle failed messages with N retries | ||
handler = new LogglyClient.Callback() {@Override | ||
public void success() { | ||
// XXX: Handle success | ||
} | ||
|
@@ -70,7 +108,7 @@ public void failure(String error) { | |
*/ | ||
@Override | ||
public void d(String message, Object... args) { | ||
log(Level.DEBUG, message, args); | ||
log(DEBUG, message, args); | ||
} | ||
|
||
/** | ||
|
@@ -81,7 +119,7 @@ public void d(String message, Object... args) { | |
*/ | ||
@Override | ||
public void d(Throwable t, String message, Object... args) { | ||
log(Level.DEBUG, message, t, args); | ||
log(DEBUG, message, t, args); | ||
} | ||
|
||
/** | ||
|
@@ -91,7 +129,7 @@ public void d(Throwable t, String message, Object... args) { | |
*/ | ||
@Override | ||
public void i(String message, Object... args) { | ||
log(Level.INFO, message, args); | ||
log(INFO, message, args); | ||
} | ||
|
||
/** | ||
|
@@ -102,7 +140,7 @@ public void i(String message, Object... args) { | |
*/ | ||
@Override | ||
public void i(Throwable t, String message, Object... args) { | ||
log(Level.INFO, message, t, args); | ||
log(INFO, message, t, args); | ||
} | ||
|
||
/** | ||
|
@@ -112,7 +150,8 @@ public void i(Throwable t, String message, Object... args) { | |
*/ | ||
@Override | ||
public void e(String message, Object... args) { | ||
log(Level.ERROR, message, args); | ||
log(ERROR, message, args); | ||
|
||
} | ||
|
||
/** | ||
|
@@ -123,7 +162,7 @@ public void e(String message, Object... args) { | |
*/ | ||
@Override | ||
public void e(Throwable t, String message, Object... args) { | ||
log(Level.ERROR, message, t, args); | ||
log(ERROR, message, t, args); | ||
} | ||
|
||
/** | ||
|
@@ -133,7 +172,8 @@ public void e(Throwable t, String message, Object... args) { | |
*/ | ||
@Override | ||
public void w(String message, Object... args) { | ||
log(Level.WARN, message, args); | ||
log(WARN, message, args); | ||
|
||
} | ||
|
||
/** | ||
|
@@ -144,7 +184,8 @@ public void w(String message, Object... args) { | |
*/ | ||
@Override | ||
public void w(Throwable t, String message, Object... args) { | ||
log(Level.WARN, message, t, args); | ||
log(WARN, message, t, args); | ||
|
||
} | ||
|
||
/** | ||
|
@@ -153,11 +194,20 @@ public void w(Throwable t, String message, Object... args) { | |
* @param message message to be logged | ||
* @param args message formatting arguments | ||
* @return JSON string | ||
* | ||
* | ||
*/ | ||
|
||
private String toJson(int level, String message, Object... args) { | ||
return String.format("{\"level\": \"%1$s\", \"message\": \"%2$s\",\"appName\" : \"%3$s\"}", | ||
LEVEL[level], | ||
String.format(message, args).replace("\"", "\\\""), String.format(appName).replace("\"", "\\\"")); | ||
} | ||
|
||
private String toJson(Level level, String message, Object... args) { | ||
return String.format("{\"level\": \"%1$s\", \"message\": \"%2$s\"}", | ||
return String.format("{\"level\": \"%1$s\", \"message\": \"%2$s\",\"appName\" : \"%3$s\"}", | ||
level, | ||
String.format(message, args).replace("\"", "\\\"")); | ||
String.format(message, args).replace("\"", "\\\""), String.format(appName).replace("\"", "\\\"")); | ||
} | ||
|
||
/** | ||
|
@@ -180,10 +230,17 @@ private String formatThrowable(Throwable t) { | |
* @return JSON string | ||
*/ | ||
private String toJson(Level level, String message, Throwable t, Object... args) { | ||
return String.format("{\"level\": \"%1$s\", \"message\": \"%2$s\", \"exception\": \"%3$s\"}", | ||
return String.format("{\"level\": \"%1$s\", \"message\": \"%2$s\", \"exception\": \"%3$s\",\"appName\" : \"%4$s\"}", | ||
level, | ||
String.format(message, args).replace("\"", "\\\""), | ||
formatThrowable(t)); | ||
formatThrowable(t), String.format(appName).replace("\"", "\\\"")); | ||
} | ||
|
||
private String toJson(int level, String message, Throwable t, Object... args) { | ||
return String.format("{\"level\": \"%1$s\", \"message\": \"%2$s\", \"exception\": \"%3$s\",\"appName\" : \"%4$s\"}", | ||
LEVEL[level], | ||
String.format(message, args).replace("\"", "\\\""), | ||
formatThrowable(t), String.format(appName).replace("\"", "\\\"")); | ||
} | ||
|
||
/** | ||
|
@@ -193,7 +250,7 @@ private String toJson(Level level, String message, Throwable t, Object... args) | |
* @param t throwable | ||
* @param args message formatting arguments | ||
*/ | ||
private void log(Level level, String message, Throwable t, Object... args) { | ||
private void log(int level, String message, Throwable t, Object... args) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @psquickitjayant why change from Level to int? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mostlyjason the new library |
||
loggly.log(toJson(level, message, t, args), handler); | ||
} | ||
|
||
|
@@ -203,7 +260,7 @@ private void log(Level level, String message, Throwable t, Object... args) { | |
* @param message message to be logged | ||
* @param args message formatting arguments | ||
*/ | ||
private void log(Level level, String message, Object... args) { | ||
private void log(int level, String message, Object... args) { | ||
loggly.log(toJson(level, message, args), handler); | ||
} | ||
|
||
|
@@ -215,7 +272,8 @@ private void log(Level level, String message, Object... args) { | |
* to clear tags | ||
*/ | ||
@Override | ||
public final void tag(String tag) { | ||
loggly.setTags(tag); | ||
protected void log(int level, String tag, String message, Throwable t) { | ||
// TODO Auto-generated method stub | ||
loggly.log(toJson(level, tag, message, t), handler); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue found: Document empty method body