Search in sources :

Example 16 with IThrowableProxy

use of ch.qos.logback.classic.spi.IThrowableProxy in project spring-cloud-gcp by spring-cloud.

the class StackdriverJsonLayout method toJsonMap.

/**
 * Convert a logging event into a Map.
 * @param event the logging event
 * @return the map which should get rendered as JSON
 */
@Override
protected Map<String, Object> toJsonMap(ILoggingEvent event) {
    Map<String, Object> map = new LinkedHashMap<>();
    if (this.includeMDC) {
        event.getMDCPropertyMap().forEach((key, value) -> {
            if (!FILTERED_MDC_FIELDS.contains(key)) {
                map.put(key, value);
            }
        });
    }
    if (this.includeTimestamp) {
        map.put(StackdriverTraceConstants.TIMESTAMP_SECONDS_ATTRIBUTE, TimeUnit.MILLISECONDS.toSeconds(event.getTimeStamp()));
        map.put(StackdriverTraceConstants.TIMESTAMP_NANOS_ATTRIBUTE, TimeUnit.MILLISECONDS.toNanos(event.getTimeStamp() % 1_000));
    }
    add(StackdriverTraceConstants.SEVERITY_ATTRIBUTE, this.includeLevel, logbackToSeverityMap.getOrDefault(event.getLevel(), Severity.DEFAULT.name()), map);
    add(JsonLayout.THREAD_ATTR_NAME, this.includeThreadName, event.getThreadName(), map);
    add(JsonLayout.LOGGER_ATTR_NAME, this.includeLoggerName, event.getLoggerName(), map);
    if (this.includeFormattedMessage) {
        String message = event.getFormattedMessage();
        if (this.includeExceptionInMessage) {
            IThrowableProxy throwableProxy = event.getThrowableProxy();
            if (throwableProxy != null) {
                String stackTrace = getThrowableProxyConverter().convert(event);
                if (stackTrace != null && !stackTrace.equals("")) {
                    message += "\n" + stackTrace;
                }
            }
        }
        map.put(JsonLayout.FORMATTED_MESSAGE_ATTR_NAME, message);
    }
    add(JsonLayout.MESSAGE_ATTR_NAME, this.includeMessage, event.getMessage(), map);
    add(JsonLayout.CONTEXT_ATTR_NAME, this.includeContextName, event.getLoggerContextVO().getName(), map);
    addThrowableInfo(JsonLayout.EXCEPTION_ATTR_NAME, this.includeException, event, map);
    addTraceId(event, map);
    add(StackdriverTraceConstants.SPAN_ID_ATTRIBUTE, this.includeSpanId, event.getMDCPropertyMap().get(StackdriverTraceConstants.MDC_FIELD_SPAN_ID), map);
    if (this.serviceContext != null) {
        map.put(StackdriverTraceConstants.SERVICE_CONTEXT_ATTRIBUTE, this.serviceContext);
    }
    if (this.customJson != null && !this.customJson.isEmpty()) {
        for (Map.Entry<String, Object> entry : this.customJson.entrySet()) {
            map.putIfAbsent(entry.getKey(), entry.getValue());
        }
    }
    addCustomDataToJsonMap(map, event);
    return map;
}
Also used : IThrowableProxy(ch.qos.logback.classic.spi.IThrowableProxy) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

IThrowableProxy (ch.qos.logback.classic.spi.IThrowableProxy)16 StackTraceElementProxy (ch.qos.logback.classic.spi.StackTraceElementProxy)4 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)3 GenericRecord (org.apache.avro.generic.GenericRecord)3 ThrowableProxy (ch.qos.logback.classic.spi.ThrowableProxy)2 IOException (java.io.IOException)2 Map (java.util.Map)2 Level (ch.qos.logback.classic.Level)1 LoggingEvent (ch.qos.logback.classic.spi.LoggingEvent)1 Gson (com.google.gson.Gson)1 JsonWriter (com.google.gson.stream.JsonWriter)1 FinishCheck (com.vip.saturn.it.base.FinishCheck)1 SimpleJavaJob (com.vip.saturn.it.job.SimpleJavaJob)1 LogbackListAppender (com.vip.saturn.it.utils.LogbackListAppender)1 JobConfig (com.vip.saturn.job.console.domain.JobConfig)1 StringWriter (java.io.StringWriter)1 LinkedHashMap (java.util.LinkedHashMap)1 Exception (org.apache.airavata.common.logging.Exception)1 LogEntry (org.apache.airavata.common.logging.LogEntry)1 Schema (org.apache.avro.Schema)1