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 Logging to seperate files 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 "Logging to seperate files" Watch "Logging to seperate files" New topic

Logging to seperate files

Aswani Kommireddy

Joined: Jul 16, 2008
Posts: 4
Hi all,

Right now our application logs everything to a same file.
But the requirement is to log to separate files i.e., when the user signs in, it should recognize the user and get the file that it should log messages. For example the file name should be like {username}.log

I am doing some research on this, but I didn't find any solution.

Two ideas come to my mind,
1) setting the log4j property at runtime and configuring it.

Properties props = new Properties();
InputStream configStream = this.getClass().getResourceAsStream("/");
String file = "whatever name I provide";

-- this is setting the property to the file name I provided and logging messages to that file. But the problems comes up when there are two users that are running the Application at same time. It is writing all messages (of all users) to the latest configured file. As it is configuring the same everytime, it holds only the latest value. Is there a way to create instances of this to each user so that he will have his own configuration?

Second idea is,
Creating a new appender to every user that signs in.
If an existing user signs in back it should look for the file that is mapped to him and write to that file.
In this case, in every class we should get that appender file(which is mapped to the user) before logging events. I dont know whether this also has the same problem that previous idea has. I have not tried this yet.

Does any of my ideas work? Is there any other solution for this?

Please help me in this regard.
I agree. Here's the link:
subject: Logging to seperate files
It's not a secret anymore!