Skip to content

Commit

Permalink
Merge pull request #144 from SAP/fix-thread
Browse files Browse the repository at this point in the history
Add Thread name to JSON log events
  • Loading branch information
KarstenSchnitter authored Mar 31, 2022
2 parents 7243fa5 + 28bd025 commit 17a1643
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public Map<String, Object> map(LogEvent event) {
fields.put(Fields.TYPE, LogEventUtilities.isRequestLog(event) ? Defaults.TYPE_REQUEST : Defaults.TYPE_LOG);
fields.put(Fields.LEVEL, String.valueOf(event.getLevel()));
fields.put(Fields.LOGGER, event.getLoggerName());
fields.put(Fields.THREAD, event.getThreadName());
if (!LogEventUtilities.isRequestLog(event) && event.getMessage() != null) {
fields.put(Fields.MSG, LogEventUtilities.getFormattedMessage(event));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public void test() {
assertThat(getField(Fields.COMPONENT_NAME), is(nullValue()));
assertThat(getField(Fields.COMPONENT_INSTANCE), is(nullValue()));
assertThat(getField(Fields.WRITTEN_TS), is(notNullValue()));
assertThat(getField(Fields.LOGGER), is(TestAppLog.class.getName()));
assertThat(getField(Fields.THREAD), is(Thread.currentThread().getName()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public Map<String, Object> map(ILoggingEvent event) {
fields.put(Fields.TYPE, isRequestLog(event) ? Defaults.TYPE_REQUEST : Defaults.TYPE_LOG);
fields.put(Fields.LEVEL, String.valueOf(event.getLevel()));
fields.put(Fields.LOGGER, event.getLoggerName());
fields.put(Fields.THREAD, event.getThreadName());
if (!isRequestLog(event)) {
fields.put(Fields.MSG, event.getFormattedMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public void test() {
assertThat(getField(Fields.COMPONENT_NAME), is("-"));
assertThat(getField(Fields.COMPONENT_INSTANCE), is("0"));
assertThat(getField(Fields.WRITTEN_TS), is(notNullValue()));
assertThat(getField(Fields.LOGGER), is(TestAppLog.class.getName()));
assertThat(getField(Fields.THREAD), is(Thread.currentThread().getName()));
assertThat(getField(Fields.CATEGORIES), is(notNullValue()));
}

Expand Down

0 comments on commit 17a1643

Please sign in to comment.