Skip to content

Structured Logging with Stack Driver Logback Appender #2669

Description

@bspradling

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!

Activity

  1. bspradling commented on Nov 30, 2017

    @bspradling
    Author

    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

  2. added
    api: loggingIssues related to the Cloud Logging API.
    priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.
    on Dec 7, 2017
  3. pongad commented on Dec 7, 2017

    @pongad
    Contributor

    @jabubake @andreamlin I'm not too sure how severe this problem is. I tagged P1, but please change if appropriate.

  4. jabubake commented on Dec 11, 2017

    @jabubake
    Contributor

    @bspradling8 : Markers is not currently supported, but we will look into adding them in a release soon.

  5. added
    priority: p2Moderately-important priority. Fix may not be included in next release.
    and removed
    priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.
    on Dec 11, 2017
  6. jabubake commented on Dec 11, 2017

    @jabubake
    Contributor
  7. pongad commented on Dec 11, 2017

    @pongad
    Contributor

    @jabubake I think @andreamlin is now working on the autogen-clients, so I think this feature is on my plate. I'll self-assign.

  8. assigned and unassigned on Dec 11, 2017
  9. added
    type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.
    and removed
    type: questionRequest for information or clarification. Not an issue.
    on Dec 13, 2017
  10. yihanzhen commented on Jan 30, 2018

    @yihanzhen
    Contributor

    Move this issue to feature backlog and close it here. The place can continue to be used for discussion.

  11. sschwell commented on Feb 1, 2021

    @sschwell

    Is this still in backlog? or has it been fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: loggingIssues related to the Cloud Logging API.priority: p2Moderately-important priority. Fix may not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions