Skip to content

JavaLoggingLogback errors do not appear in StackDriver Error Reporting #30

@rich-j

Description

@rich-j

The documentation for StackDriver Java Error Reporting states:

Exceptions logged using the Stackdriver Logback Appender ... are automatically reported to the Error Reporting console.

None of our logged errors appear in Error Reporting (not that we have many :-) .

We are using Java 11 in App Engine Standard with version 0.116.0-alpha of this google-cloud-logging-logback appender. Our logback.xml configuration is:

<appender name="CLOUD" class="com.google.cloud.logging.logback.LoggingAppender">
  <log>application.log</log>
  <resourceType>gae_app</resourceType> <!-- Optional : default global -->
  <flushLevel>WARN</flushLevel> <!-- Optional : default ERROR -->
</appender>

We did a quick experiment using Formatting errors in Stackdriver Logging and were able to get errors reported by changing the appender to submit JSON and add the @type value for errors:

private LogEntry logEntryFor(ILoggingEvent e) {
    StringBuilder payload = new StringBuilder(e.getFormattedMessage()).append('\n');
    writeStack(e.getThrowableProxy(), "", payload);

    Level level = e.getLevel();
    Severity severity = severityFor(level);

    Map<String, Object> jsonContent = new HashMap<String, Object>();
    jsonContent.put("message", payload.toString().trim());
    if (severity == Severity.ERROR)
      jsonContent.put("@type", "type.googleapis.com/google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent");

    LogEntry.Builder builder =
        LogEntry.newBuilder(Payload.JsonPayload.of(jsonContent))
            .setTimestamp(e.getTimeStamp())
            .setSeverity(severity);

...

Having logged errors appear in Error Reporting is important for any production server.

Metadata

Metadata

Assignees

Labels

api: loggingIssues related to the googleapis/java-logging-logback API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions