Skip to content
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

feat: add label fullStacktrace #40

Merged
merged 2 commits into from Dec 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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