简体   繁体   English

部署到Jetty的每场战争的单独日志文件

[英]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-*.jarlogback-classic-*.jarlogback-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. 我想将每个战争日志和码头自己的日志写到单独的文件中。

  1. Logging framework does not matter, I can use something different, than logback if it helps. 日志记录框架无关紧要,如果有帮助,我可以使用与logback不同的方法。
  2. I've already read "Logging Separation" chapter in logback docs. 我已经阅读了logback文档中的“日志记录分隔”一章。 This forces me to change my web.xml and add logback jars to war, so this is not, what I want. 这迫使我更改了web.xml并向战争添加了logback jar,所以这不是我想要的。
  3. I've already read "Jetty/Tutorial/Sifting Logs with Logback". 我已经阅读了“ Jetty / Tutorial /使用Logback筛选日志”。 It is about separating by hotstname and not by application, so it does not help also. 它是关于按hotstname而不是按应用程序进行分隔,因此也无济于事。

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.

相关问题 每个租户的单独日志文件 - Separate log file for each tenant 如何从部署在同一tomcat中的另一个war文件重新配置war文件的log4j - How to reconfigure log4j of a war file from another war file deployed in same tomcat 为for循环中的每次迭代创建单独的日志文件 - Create a separate log file for each iteration in a for loop 使用log4j为每个应用程序创建单独的日志文件 - Creating separate log file for each application with log4j 对每个Pentaho数据集成作业(水壶)使用单独的日志文件 - Use a separate log file for each Pentaho Data Integration Job (kettle) 有没有办法为每个用户创建一个单独的日志文件? (弹簧靴) - Is there a way to create a separate log file for each user ? (spring boot) 如何为类的每个实例编写单独的日志文件? - How to write separate log file for each instance of a class? 使用模式 AWS Cloudwatch 为每个文件创建单独的日志 stream - Create separate log stream for each file with pattern AWS Cloudwatch 如何创建保存日志文件的路径? 每次都保存在单独的日志文件中? - How to create a path for saving the log file? And save in separate log file each time? 部署时的GWT日志文件 - GWT log file when deployed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM