将 2 个 Web 应用程序记录到 2 个不同的文件中
我在 tomcat 中从同一源树构建了 2 个 Web 应用程序,每个应用程序都使用 PropertyConfigurator 加载各自的 /webapp/WEB-INF/classes/log4j.properties
。
目前,tomcat 配置为对整个容器使用一个控制台附加程序,并且两个应用程序的 log4js 都只写入控制台:
log4j.rootCategory=info, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
这意味着我最终会为整个容器提供一个大的 catalina.out
。
我想配置每个应用程序 log4js,以便它们附加到自己单独的滚动文件中。
我知道我可以在 log4j.properties
中使用系统属性替换,但是系统属性不是在虚拟机之间共享的,因此容器内的两个应用程序之间不是线程安全的吗?
有人可以建议一个整洁的解决方案,它允许我将两个应用程序配置为记录到单独的文件,最好在日志文件名中使用应用程序的上下文名称。
谢谢,p。
I have 2 web applications built from the same source tree within tomcat, which each use a PropertyConfigurator loading their respective /webapp/WEB-INF/classes/log4j.properties
.
Currently tomcat is configured to use one console appender for the whole container, and both app's log4js just write to the console:
log4j.rootCategory=info, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
This means I end up with one big catalina.out
for the whole container.
I would like to configure each of the applications log4js so that they append to their own separate rolling files.
I'm aware I can use system properties substitution within log4j.properties
however isn't system properties shared across the VM and therefore not threadsafe between the 2 applications within the container?
Can someone suggest a tidy solution which allows me to configure the 2 applications to log to separate files, preferably with the application's context name within the log's file name.
thanks, p.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的 log4j.jar 和 commons-logging.jar 放在 tomcat 目录中的什么位置?您使用的是哪个版本的 tomcat?
如果你在 common/lib 中有这些 jar 的一份副本,那么所有日志记录肯定都会使用 catalina.log ,因为 tomcat 的 log4j.properties 文件只是为其下的服务器和 Web 应用程序配置的文件。
假设此方案在您的情况下有效,请复制两个 Web 应用程序的 WEB-INF/lib 下的 log4j.jar 和 common-logging.jar。
对于在日志文件名中使用应用程序名称,由于每个应用程序使用单独的 log4j.properties 文件,因此请在 log4j.properties 文件中根据 FileAppender 或 RollingFileAppender 命名您的日志文件。
Where is your log4j.jar and commons-logging.jar placed in tomcat directory? And which version of tomcat you are using?
If you have one copy of these jar inside common/lib than surely catalina.log would be used by all logging since tomcat's log4j.properties file is only the one getting configured for both server and webapps under it.
Assuming this scenario holds valid in your case, copy log4j.jar and common-logging.jar under WEB-INF/lib for both web applications.
For using application name within log's file name, since separate log4j.properties file is used for each application, name your logfiles as you like in log4j.properties file against FileAppender or RollingFileAppender.