Skip to content

Commit

Permalink
feat: add label fullStacktrace (#40)
Browse files Browse the repository at this point in the history
* feat: add label fullStacktrace

* feat: fix review changes
  • Loading branch information
athakor committed Dec 13, 2019
1 parent 5e5c129 commit 43e1953
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Expand Up @@ -72,6 +72,7 @@ public class LoggingAppender extends UnsynchronizedAppenderBase<ILoggingEvent> {
private static final String LEVEL_NAME_KEY = "levelName";
private static final String LEVEL_VALUE_KEY = "levelValue";
private static final String LOGGER_NAME_KEY = "loggerName";
private static final String STACKTRACE = "fullStacktrace";

private volatile Logging logging;
private LoggingOptions loggingOptions;
Expand Down Expand Up @@ -269,14 +270,15 @@ private LogEntry logEntryFor(ILoggingEvent e) {

Level level = e.getLevel();
LogEntry.Builder builder =
LogEntry.newBuilder(Payload.StringPayload.of(payload.toString().trim()))
LogEntry.newBuilder(Payload.StringPayload.of(e.getMessage().trim()))
.setTimestamp(e.getTimeStamp())
.setSeverity(severityFor(level));

builder
.addLabel(LEVEL_NAME_KEY, level.toString())
.addLabel(LEVEL_VALUE_KEY, String.valueOf(level.toInt()))
.addLabel(LOGGER_NAME_KEY, e.getLoggerName());
.addLabel(STACKTRACE, payload.toString().trim());

for (Map.Entry<String, String> entry : e.getMDCPropertyMap().entrySet()) {
if (null != entry.getKey() && null != entry.getValue()) {
Expand Down
Expand Up @@ -87,6 +87,7 @@ public void testFlushLevelConfigUpdatesLoggingFlushSeverity() {
.put("levelName", "WARN")
.put("levelValue", String.valueOf(30000L))
.put("loggerName", this.getClass().getName())
.put("fullStacktrace", "this is a test".trim())
.build())
.build();
logging.setFlushSeverity(Severity.WARNING);
Expand All @@ -112,9 +113,10 @@ public void testFilterLogsOnlyLogsAtOrAboveLogLevel() {
.setSeverity(Severity.ERROR)
.setLabels(
new ImmutableMap.Builder<String, String>()
.put("levelName", "ERROR")
.put("levelValue", String.valueOf(40000L))
.put("loggerName", this.getClass().getName())
.put("levelName","ERROR")
.put("levelValue",String.valueOf(40000L))
.put("loggerName",this.getClass().getName())
.put("fullStacktrace","this is a test".trim())
.build())
.build();
logging.setFlushSeverity(Severity.ERROR);
Expand Down Expand Up @@ -150,6 +152,7 @@ public void testEnhancersAddCorrectLabelsToLogEntries() {
.put("levelName", "WARN")
.put("levelValue", String.valueOf(30000L))
.put("loggerName", this.getClass().getName())
.put("fullStacktrace", "this is a test".trim())
.put("test-label-1", "test-value-1")
.put("test-label-2", "test-value-2")
.build())
Expand Down Expand Up @@ -199,6 +202,7 @@ public void testMdcValuesAreConvertedToLabels() {
.put("levelName", "INFO")
.put("levelValue", String.valueOf(20000L))
.put("loggerName", this.getClass().getName())
.put("fullStacktrace", "this is a test".trim())
.put("mdc1", "value1")
.put("mdc2", "value2")
.build())
Expand Down

0 comments on commit 43e1953

Please sign in to comment.