I want to log each request and response in dropwizard into different files. For example I want all the requests to be logged in /var/log/applicationname-request.log and all responses into /var/log/applicationname-response.log
Is there any way in which we can achieve the same?
Unfortunately DropWizard currently doesn't support this natively. See this lively discussion for more information.
Fortunately there's a workaround if you're willing to forego configuring logging with DropWizard all together. Somewhere in your
run
method call the following code to reset the logging and reconfigure it using sfl4j's standard mechanism:Then you can configure logging by adding
logback.xml
to your classpath and configuring it something like this:Then you can grab those corresponding loggers in your resource and log away: