• 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 into different files based on parameters

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
I don't always make ads but when I do they're tiny
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic