简体   繁体   中英

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

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); 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.

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. (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. The solution of Stultuske is more appropriate.

您需要指定文件名:

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

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