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

io.dropwizard.logging.json.layout.AbstractJsonLayout Maven / Gradle / Ivy

package io.dropwizard.logging.json.layout;

import ch.qos.logback.core.LayoutBase;

import javax.annotation.Nullable;
import java.util.Map;

/**
 * Provides the common functionality for building JSON representations
 * of {@link ch.qos.logback.access.spi.IAccessEvent} and {@link ch.qos.logback.classic.spi.ILoggingEvent}
 * events.
 *
 * @param  represents the type of the event
 */
public abstract class AbstractJsonLayout extends LayoutBase {

    private final JsonFormatter jsonFormatter;

    protected AbstractJsonLayout(JsonFormatter jsonFormatter) {
        this.jsonFormatter = jsonFormatter;
    }

    @Override
    @Nullable
    public String doLayout(E event) {
        return jsonFormatter.toJson(toJsonMap(event));
    }

    /**
     * Converts the provided logging event to a generic {@link Map}
     */
    protected abstract Map toJsonMap(E event);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy