File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Open Source Projects and the fly likes Getting log4j to write to multiple log files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Getting log4j to write to multiple log files" Watch "Getting log4j to write to multiple log files" New topic

Getting log4j to write to multiple log files

Dave Trower
Ranch Hand

Joined: Feb 12, 2003
Posts: 86
I am writing a Tomcat application that uses log4j.
I want to create several logs to several differant files.
I tried creating several loggers with differant names and these loggers used differant conifiguration property files but when I change the settings for one logger it changes it for all the logggers.
Guy Allard
Ranch Hand

Joined: Nov 24, 2000
Posts: 776
Assuming you want to create different log files for code in different Java packages, this is fairly easy. You only need one log4j configuration file.

Here is an example that should get you started. Watch what is commented out, this is a cut and paste of current config.

[ November 17, 2007: Message edited by: Guy Allard ]
Mohan Karthick
Ranch Hand

Joined: Apr 11, 2005
Posts: 199
I tried this but not working I simply run a java application in a loop which is calling and, want to create log for x.log and y.log calling both the classes from main method, logs are mixing up I am using DOMConfigurator static block.
I agree. Here's the link:
subject: Getting log4j to write to multiple log files
It's not a secret anymore!