I'm using the Spark web framework to develop a REST API. Is there a way to automatically log all incoming requests and outgoing responses (query params, headers, status codes, etc) or do I need to manually add logging for each one of the handlers?
The Spark documentation has nothing on this subject.
Thanks.
Here's was my workaround.
private static String requestInfoToString(Request request) {
StringBuilder sb = new StringBuilder();
sb.append(request.requestMethod());
sb.append(" " + request.url());
sb.append(" " + request.body());
return sb.toString();
}
public static void main(String[] args) {
// Bunch of handlers
before((request, response) -> {
log.info(requestInfoToString(request));
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With