• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Logging to seperate files

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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("/log4j.properties");
props.load(configStream);
String file = "whatever name I provide";
props.setProperty("log4j.appender.A.File",file);
PropertyConfigurator.configure(props);

-- 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 log4j.properties everytime, it holds only the latest value. Is there a way to create instances of this log4j.properties 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.
 
Water proof donuts! Eat them while reading this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic