io.dropwizard.request.logging.layout.LogbackAccessRequestLayout Maven / Gradle / Ivy
package io.dropwizard.request.logging.layout;
import ch.qos.logback.access.PatternLayout;
import ch.qos.logback.core.Context;
import java.util.TimeZone;
/**
* A base layout for Logback Access request logs.
*
* - Extends {@link PatternLayout}.
* - Disables pattern headers.
* - Sets the pattern to the given timezone.
*
*/
public class LogbackAccessRequestLayout extends PatternLayout {
static {
// Replace the buggy default converter which don't work async appenders
defaultConverterMap.put("requestParameter", SafeRequestParameterConverter.class.getName());
defaultConverterMap.put("reqParameter", SafeRequestParameterConverter.class.getName());
}
public LogbackAccessRequestLayout(Context context, TimeZone timeZone) {
setOutputPatternAsHeader(false);
setPattern("%h %l %u [%t{dd/MMM/yyyy:HH:mm:ss Z," + timeZone.getID()
+ "}] \"%r\" %s %b \"%i{Referer}\" \"%i{User-Agent}\" %D");
setContext(context);
}
}