Structured Logging with Stack Driver Logback Appender
Currently there is a Java Logback Appender that allows Java Applications to utilize the SLF4J interface and log to StackDriver.
SLF4J has the concept of Marker objects that allows users to include objects to enrich the log messages. It seems that the StackDriver Logback Appender is ignoring these Marker objects while logging to StackDriver.
To show an example, the following log statement:
logger.with(anObject).info("The request was successful");
will result a Logstash with the following structure:
{
labels: { ... labels here ... },
logName: 'java.log',
resource: { ... resource here ... },
severity: 'INFO',
textPayload: "The request was successful",
timestamp: "2017-11-30T01:21:59.205Z
}
It seems like the Appender is completely ignoring these Marker objects when the should be getting jumped into the jsonPayload attribute of the com.google.logging LogEntry class.
Any help surrounding getting structured logging working with the StackDriver Logback Appender working would be greatly appreciated!
As an update, it appears the issue would be here:
private LogEntry logEntryFor(ILoggingEvent e) {
String payload = e.getFormattedMessage();
Level level = e.getLevel();
LogEntry.Builder builder =
LogEntry.newBuilder(Payload.StringPayload.of(payload))
.setTimestamp(e.getTimeStamp())
.setSeverity(severityFor(level));
builder
.addLabel(LEVEL_NAME_KEY, level.toString())
.addLabel(LEVEL_VALUE_KEY, String.valueOf(level.toInt()));
if (loggingEnhancers != null) {
for (LoggingEnhancer enhancer : loggingEnhancers) {
enhancer.enhanceLogEntry(builder);
}
}
return builder.build();
}
It assumes that all data coming into the LoggingEvent is a StringPayload
@jabubake @andreamlin I'm not too sure how severe this problem is. I tagged P1, but please change if appropriate.
@bspradling8 : Markers is not currently supported, but we will look into adding them in a release soon.
@dzlier-gcp FYI
@jabubake I think @andreamlin is now working on the autogen-clients, so I think this feature is on my plate. I'll self-assign.
Move this issue to feature backlog and close it here. The place can continue to be used for discussion.
Is this still in backlog? or has it been fixed?