File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Logging into different files based on parameters

 
Vishnu Vardhan
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to log into two different files based on a value of a varaiable in my Java program

Example : if(value = "abc") log into abcd.txt
else if (value = "xyz") log into xyzz.txt

Can any one help me out please.

Vishnu
 
Paul Clapham
Sheriff
Pie
Posts: 20177
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The if-statements seem like a good start. But you have a problem? I can't see what it is. Can you explain a bit more?
 
Vishnu Vardhan
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,

Actually my Java program handles requests from two systems. System A and system B. Currently I am logging all the logs into a single file using log4J.

No I want to seperate it. When I process requests from system A they must go to a.log and when I process requests from system B they must go to b.log.

I hope it is clear now.

Thanks
-Vishnu
 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can have 2 separate loggers in your java code. Each logger will use a separate appender. To avoid code duplication(of the if/else statements in each class where you are using the logger), i would suggest, you create your own wrapper over the log4j's Logger. Something like:



And the classes using the logger will look like:





Your log4j.xml will look like:



The above method looks simple. However, you might want to have a look at some other ways to tackle this, mentioned at Logging Separation and see if they are better suited in your application
[ July 12, 2006: Message edited by: jaikiran pai ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic