I have a web application packaged as war file, which uses slf4j as a logging facade. It depends on slf4j-api-*.jar
, but does not contain one inside. I want to deploy this war to Jetty and configure logging on web container side.
I've put slf4j-api-*.jar
, logback-classic-*.jar
and logback-core-*.jar
to ${jetty.home}/lib/ext
and logback.xml
to ${jetty.home}/resources
, which I configured to write logs to ${jetty.home}/logs/jetty.log
.
This works perfectly, but I have everything logged to jetty.log
. I want to write each war log and jetty's own log to separate file.
In the documentation, Sifting Logs with LogBack , the example uses the slf4j MDC to setup "host" as the split. You can use any split choice you want to with your own MDCHandler .
Since the key is to use the MDCHandler, it has to be able to mine for any information present in the incoming Request object. (the reason for this, is that the MDCHandler is not a participant of the servlet scoping and contexts for the webapp itself, as it sits in front of it)
One technique is to use the request.getContextPath() to split on the whatever context your webapp have been deployed to.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.