Package org.zalando.logbook.json
Class JsonHttpLogFormatter
java.lang.Object
org.zalando.logbook.json.JsonHttpLogFormatter
- All Implemented Interfaces:
HttpLogFormatter,StructuredHttpLogFormatter
@API(status=STABLE) public final class JsonHttpLogFormatter extends java.lang.Object implements StructuredHttpLogFormatter
A custom
HttpLogFormatter that produces JSON objects. It can be augmented with composition:
public class CustomsFormatter implements HttpLogFormatter {
private final JsonHttpLogFormatter delegate;
public CustomsFormatter(ObjectMapper mapper) {
this.delegate = new JsonHttpLogFormatter(mapper);
}
public String format(Precorrelation precorrelation, HttpRequest request) throws IOException {
Map<String, Object> content = delegate.prepare(precorrelation, request);
// modify request here
return delegate.format(content);
}
public String format(Correlation correlation, HttpResponse response) throws IOException {
Map<String, Object> content = delegate.prepare(correlation, response);
// modify response here
return delegate.format(content);
}
}
-
Constructor Summary
Constructors Constructor Description JsonHttpLogFormatter()JsonHttpLogFormatter(com.fasterxml.jackson.databind.ObjectMapper mapper) -
Method Summary
Modifier and Type Method Description java.lang.Stringformat(java.util.Map<java.lang.String,java.lang.Object> content)java.util.Optional<java.lang.Object>prepareBody(HttpMessage message)Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.zalando.logbook.StructuredHttpLogFormatter
format, format, prepare, prepare, prepareHeaders
-
Constructor Details
-
JsonHttpLogFormatter
public JsonHttpLogFormatter() -
JsonHttpLogFormatter
public JsonHttpLogFormatter(com.fasterxml.jackson.databind.ObjectMapper mapper)
-
-
Method Details
-
prepareBody
public java.util.Optional<java.lang.Object> prepareBody(HttpMessage message) throws java.io.IOException- Specified by:
prepareBodyin interfaceStructuredHttpLogFormatter- Throws:
java.io.IOException
-
format
public java.lang.String format(java.util.Map<java.lang.String,java.lang.Object> content) throws java.io.IOException- Specified by:
formatin interfaceStructuredHttpLogFormatter- Throws:
java.io.IOException
-