[英]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. 我有一个打包为war文件的Web应用程序,它使用slf4j作为日志记录外观。 It depends on slf4j-api-*.jar
, but does not contain one inside. 它取决于slf4j-api-*.jar
,但其中不包含一个。 I want to deploy this war to Jetty and configure logging on web container side. 我想将这场战争部署到Jetty并在Web容器端配置日志记录。
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
. 我已将slf4j-api-*.jar
, logback-classic-*.jar
和logback-core-*.jar
logback.xml
${jetty.home}/lib/ext
,将logback.xml
${jetty.home}/resources
,我将其配置为将日志写入${jetty.home}/logs/jetty.log
。
This works perfectly, but I have everything logged to jetty.log
. 这可以正常工作,但是我已将所有内容记录到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. 在文档“ 使用LogBack筛选日志”中 ,该示例使用slf4j MDC将“主机”设置为拆分。 You can use any split choice you want to with your own MDCHandler . 您可以将任何想要的拆分选项与自己的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. 由于关键是使用MDCHandler,因此它必须能够挖掘传入的Request对象中存在的任何信息。 (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) (其原因是,MDCHandler不在webapp本身的servlet范围和上下文的参与者,因为它位于它的前面)
One technique is to use the request.getContextPath() to split on the whatever context your webapp have been deployed to. 一种技术是使用request.getContextPath()在已部署Web应用程序的任何上下文上进行拆分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.