This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Other Open Source Projects and the fly likes log to differnt files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "log to differnt files" Watch "log to differnt files" New topic

log to differnt files

Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362

I have to log the logs from 2 differnt packages to differnt log files. How do I set the config in

package has to go to log1.log and package except , all other package like has to go to log2.log

Any ideas please?
Travis Hein
Ranch Hand

Joined: Jun 06, 2006
Posts: 161
I really don't know how to do that with the Now, log4j does support using an log4j.xml file to set it up. usually its the same kind of convenience, of just dropping the log4j.xml into the top of the classpath instead of (remove and replace) the Or if you do any other kind of elaborate set up logging by system property to log4j config file path.

The log4j.xml is more flexible, and powerful for setting up more elaborate kinds of things like different log files by package as you are looking to do.

Have a look at

they have an example towards the end where using the log4j.xml to do package specific logging.

Error: Keyboard not attached. Press F1 to continue.
Carol Enderlin
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Where are you stuck? Are you using the additivity flag to keep logging out of log2.log?

After you define logger/appender for set additivity false on : = false

You can search on additivity in this forum for examples.
Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362
Here is my log4j file

As you can see form the file, I want to go to log2.log and all the remaining package logs to go to log1.log.

Thanks in advance

Tanzy Akhtar
Ranch Hand

Joined: Jul 19, 2009
Posts: 110
Hi Mary,

One idea i have and applied in my project.

Do as follows--

1. Create a class with logger and create methods which call nothing but DEBUG()/INFO()/ ... etc.
2. Configure the above created class in log4j.propertis/log4j.xml.
3. Now call the above created methods to log messages other than package

For full details you may follow this.
Don't get confused by the subject line used in the given url, what i described above, is available there.


Roll with punchers, there is always tomorrow.
Techie Blog --
Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362
Thanks for your reply tanzy akhtar...I am not allowed to write any java class for this.. Below config worked fine for me

Tanzy Akhtar
Ranch Hand

Joined: Jul 19, 2009
Posts: 110
That's really great that the problem has been resolved. Congrats.
And thanks for sharing the solution.
subject: log to differnt files
Similar Threads
How to use different logging in different packages with log4j?
subclass outside package
Logging Package Specific logs using LOG4J
inherited protected member
How to set up multiple log4j configurations for multiple WAR packages?