简体   繁体   中英

Separate log file for each war deployed to Jetty

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.

  1. Logging framework does not matter, I can use something different, than logback if it helps.
  2. I've already read "Logging Separation" chapter in logback docs. This forces me to change my web.xml and add logback jars to war, so this is not, what I want.
  3. I've already read "Jetty/Tutorial/Sifting Logs with Logback". It is about separating by hotstname and not by application, so it does not help also.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM