io.dropwizard.logging.json.AbstractJsonLayoutBaseFactory Maven / Gradle / Ivy
package io.dropwizard.logging.json;
import ch.qos.logback.core.spi.DeferredProcessingAware;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.dropwizard.jackson.Jackson;
import io.dropwizard.logging.json.layout.JsonFormatter;
import io.dropwizard.logging.json.layout.TimestampFormatter;
import io.dropwizard.logging.layout.DiscoverableLayoutFactory;
import javax.annotation.Nullable;
import javax.validation.constraints.NotNull;
import java.util.Collections;
import java.util.Map;
import java.util.TimeZone;
/**
*
*
* Name
* Default
* Description
*
*
* {@code timestampFormat}
* (none)
* By default, the timestamp is not formatted; To format the timestamp using set the property with the
* corresponding {@link java.time.format.DateTimeFormatter} string, for example, {@code yyyy-MM-ddTHH:mm:ss.SSSZ}
*
*
* {@code prettyPrint}
* {@code false}
* Whether the JSON output should be formatted for human readability.
*
*
* {@code appendLineSeparator}
* {@code true}
* Whether to append a line separator at the end of the message formatted as JSON.
*
*
* {@code customFieldNames}
* empty
* A map of field name replacements. For example:
* (requestTime:request_time, userAgent:user_agent)
*
*
* {@code additionalFields}
* empty
* A map of fields to add.
*
*
*/
public abstract class AbstractJsonLayoutBaseFactory
implements DiscoverableLayoutFactory {
@Nullable
private String timestampFormat;
private boolean prettyPrint;
private boolean appendLineSeparator = true;
@NotNull
private Map customFieldNames = Collections.emptyMap();
@NotNull
private Map additionalFields = Collections.emptyMap();
@JsonProperty
@Nullable
public String getTimestampFormat() {
return timestampFormat;
}
@JsonProperty
public void setTimestampFormat(String timestampFormat) {
this.timestampFormat = timestampFormat;
}
@JsonProperty
public boolean isPrettyPrint() {
return prettyPrint;
}
@JsonProperty
public void setPrettyPrint(boolean prettyPrint) {
this.prettyPrint = prettyPrint;
}
@JsonProperty
public boolean isAppendLineSeparator() {
return appendLineSeparator;
}
@JsonProperty
public void setAppendLineSeparator(boolean appendLineSeparator) {
this.appendLineSeparator = appendLineSeparator;
}
@JsonProperty
public Map getCustomFieldNames() {
return customFieldNames;
}
@JsonProperty
public void setCustomFieldNames(Map customFieldNames) {
this.customFieldNames = customFieldNames;
}
@JsonProperty
public Map getAdditionalFields() {
return additionalFields;
}
@JsonProperty
public void setAdditionalFields(Map additionalFields) {
this.additionalFields = additionalFields;
}
protected JsonFormatter createDropwizardJsonFormatter() {
return new JsonFormatter(Jackson.newObjectMapper(), isPrettyPrint(), isAppendLineSeparator());
}
protected TimestampFormatter createTimestampFormatter(TimeZone timeZone) {
return new TimestampFormatter(getTimestampFormat(), timeZone.toZoneId());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy