Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Logging to seperate files  RSS feed

Aswani Kommireddy
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!