-
Notifications
You must be signed in to change notification settings - Fork 30
Closed
Labels
api: loggingIssues related to the googleapis/java-logging-logback API.Issues related to the googleapis/java-logging-logback API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-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.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Description
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.Issues related to the googleapis/java-logging-logback API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-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.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.