All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.smilego.tenant.logging.logback.LoggingEvent Maven / Gradle / Ivy

package io.smilego.tenant.logging.logback;

import ch.qos.logback.classic.spi.ILoggingEvent;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Map;

@Data
@NoArgsConstructor
public class LoggingEvent {
    @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
    private LocalDateTime ts;
    private String level;
    private String logger;
    private String thread;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String stackTrace;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Map mdc;
    private Object content;

    public LoggingEvent(ILoggingEvent event){

        this.ts = LocalDateTime.ofInstant(Instant.ofEpochMilli(event.getTimeStamp()), ZoneId.systemDefault());
        this.content = event.getFormattedMessage();
        this.level = event.getLevel().toString();
        this.logger = event.getLoggerName();
        this.thread = event.getThreadName();
        Map mdc = event.getMDCPropertyMap();

        if (mdc != null && !mdc.isEmpty()) this.mdc = mdc;

        if (event.hasCallerData()) {
            StackTraceElement st = event.getCallerData()[0];
            this.stackTrace = String.format("%s.%s:%d", st.getClassName(), st.getMethodName(), st.getLineNumber());
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy