简体   繁体   English

每个项目的Log4j日志文件

[英]Log4j log file per project

I have 9 tomcat projects running with log4j implemented, now how can I have different log file for each project with using same log4j.properties file 我有9个运行了log4j的tomcat项目,现在如何使用相同的log4j.properties文件为每个项目使用不同的日志文件

with my following settings it is creating different files but logs are written in one file 使用我的以下设置,它正在创建不同的文件,但是日志被写入一个文件

log = /usr/logs
log4j.rootLogger = DEBUG, FILE

log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=${log}/std.out

log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%d [%-5p] [%C] [%t] [%L] - [%m] %n

before PropertyConfigurator.configure(props); PropertyConfigurator.configure(props);之前PropertyConfigurator.configure(props); i am updating following property and hence a file is created for but how can I make these settings to write logs to the respective log files 我正在更新以下属性,因此创建了一个文件,但是如何进行这些设置以将日志写入相应的日志文件

log4j.appender.FILE.File

especially when working on big projects, having seperate instances of Tomcat running can come in handy: if you mess up the server config for one project, doesn't mean the others won't run anymore, and, just because the config for one project needs to change, doesn't mean the config for other projects should. 尤其是在大型项目上工作时,运行单独的Tomcat实例会派上用场:如果您弄乱了一个项目的服务器配置,并不意味着其他项目就不再运行,并且,因为一个项目的配置需要更改,并不意味着其他项目的配置应该更改。

if you have to run those applications continuously (not likely, but still) you may want to re-boot your containers from time to time, might be good if you don't put all your projects 'offline' at the same time. 如果您必须连续运行这些应用程序(不太可能,但仍然要运行),则可能需要不时重新启动容器,如果您不同时将所有项目置于“离线”状态,则可能会很好。

but, in your case, the most beneficial difference would be: for each single Tomcat installation (which only takes a few mb anyway, it's not as if you're going to run out of disk space), you can specify a separate log file. 但是,对于您而言,最有利的区别是:对于每个单独的Tomcat安装(无论如何只需要几mb,这似乎并不会导致磁盘空间用完),您可以指定一个单独的日志文件。 (do remember to use different ports when doing this, though, otherwise you won't be able to run them simultaneously) (不过,请记住在执行此操作时使用不同的端口,否则您将无法同时运行它们)

If really needed, you can have separate loggers defined in one log4j configuration, but that has to be supported by your application, which has to be able to pick up the correct logger. 如果确实需要,您可以在一个log4j配置中定义单独的记录器,但是您的应用程序必须支持该配置,该应用程序必须能够选择正确的记录器。 The solution of Stultuske is more appropriate. Stultuske的解决方案更为合适。

您需要指定文件名:

log4j.appender.File.File=/location/nameLogFile.log

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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