wood burning stoves 2.0*
The moose likes Other Open Source Projects and the fly likes log4j: seperate logfiles for multiple threads. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "log4j: seperate logfiles for multiple threads." Watch "log4j: seperate logfiles for multiple threads." New topic
Author

log4j: seperate logfiles for multiple threads.

peter cooke
Ranch Hand

Joined: Mar 16, 2004
Posts: 314
My project will have some number of class "foo" each running in a seperate thread. (foo implements runnable).

as each instance of foo runs, it may want to log a message to a file. I want the out put of each instances log request to go to a seperate file.

Searching for google; I have found several people asking how to solve this problem using log4j, I have not found an aswer yet. someone mentioned extending FileAppender, but I don't comprehend what to do.

Any suggestions.


CIAO Peter M. Cooke
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
Not sure what to suggest here....
From the documentation I read, I see that there are ways to add different Appenders so you can write to different files (using FileAppender class). But I haven't seen a way to add different Appenders dynamically, which seems to be what you want to do.

If I am not mistaken, and if I can re-phrase your question -
You want to add a different FileAppender to different threads?
Is that right?

I did some testing with the addAppender("fileName") message but I wasn't able to create a log file. I ended up using the log4J.xml file method discussed in the other posts here.

I will try to give it one more try and update if I find anything new.
[Sorry, not a solution to your problem, but just thinking out loud.]

- m


Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
Ok, here's what I would do -

Extend one of the FileAppender classes (RolloginFileAppender or DailyRol...).
Add an attribute MyLogType - much like the Level.
Implement logic based on MyLogType values, assuming you are familiar with the logic of Level.
On your foo class, add the same attribute and set its value.

Just follow the same concept as what Log4J does with Level.
Any other thoughts are most welcome.

- m
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: log4j: seperate logfiles for multiple threads.