io.dropwizard.logging.json.AccessJsonLayoutBaseFactory Maven / Gradle / Ivy
package io.dropwizard.logging.json;
import ch.qos.logback.access.spi.IAccessEvent;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.core.LayoutBase;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.google.common.collect.ImmutableSet;
import io.dropwizard.logging.json.layout.AccessJsonLayout;
import java.util.EnumSet;
import java.util.Set;
import java.util.TimeZone;
/**
*
*
* Name
* Default
* Description
*
*
* {@code includes}
* (timestamp, remoteAddress,requestTime, requestUri, statusCode, method, protocol, contentLength, userAgent))
* Set of logging event attributes to include in the JSON map.
*
*
* {@code requestHeaders}
* (empty)
* Set of request headers included in the JSON map as the ``headers`` field.
*
*
* {@code responseHeaders}
* (empty)
* Set of response headers included in the JSON map as the ``responseHeaders`` field.
*
*
*/
@JsonTypeName("access-json")
public class AccessJsonLayoutBaseFactory extends AbstractJsonLayoutBaseFactory {
private EnumSet includes = EnumSet.of(AccessAttribute.REMOTE_ADDRESS,
AccessAttribute.REMOTE_USER, AccessAttribute.REQUEST_TIME, AccessAttribute.REQUEST_URI,
AccessAttribute.STATUS_CODE, AccessAttribute.METHOD, AccessAttribute.PROTOCOL, AccessAttribute.CONTENT_LENGTH,
AccessAttribute.USER_AGENT, AccessAttribute.TIMESTAMP);
private Set responseHeaders = ImmutableSet.of();
private Set requestHeaders = ImmutableSet.of();
@JsonProperty
public Set getResponseHeaders() {
return responseHeaders;
}
@JsonProperty
public void setResponseHeaders(Set responseHeaders) {
this.responseHeaders = responseHeaders;
}
@JsonProperty
public Set getRequestHeaders() {
return requestHeaders;
}
@JsonProperty
public void setRequestHeaders(Set requestHeaders) {
this.requestHeaders = requestHeaders;
}
@JsonProperty
public EnumSet getIncludes() {
return includes;
}
@JsonProperty
public void setIncludes(EnumSet includes) {
this.includes = includes;
}
@Override
public LayoutBase build(LoggerContext context, TimeZone timeZone) {
final AccessJsonLayout jsonLayout = new AccessJsonLayout(createDropwizardJsonFormatter(),
createTimestampFormatter(timeZone), includes, getCustomFieldNames(), getAdditionalFields());
jsonLayout.setContext(context);
jsonLayout.setRequestHeaders(requestHeaders);
jsonLayout.setResponseHeaders(responseHeaders);
return jsonLayout;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy