Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Log4j : How to name the logfile dynamically

 
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I want to have the name of my log file to be decided at run time.
Like, suppose a command line argument is to be included in the log file name.
How to do it, declaratively..i.e. using log4j.properties file or log4j.xml file ?

This is how it can be done, programmatically :-



It has to be rolled.
I feel it is quite a common requirement, whenever you want to run your program everyday, for different args passed to it.
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use system property on the command line

-Dfoo=bar

Then in the properties or xml config file grab the value of foo with ${foo}
 
Mishra Anshu
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Carol !

I think, since I decide the name of the logfile depending upon what is passed as args, I would use :-

System.setProperty("foo","whatEverName"+args[0]);

Thanks
[ October 19, 2006: Message edited by: Mishra Anshu ]
 
Carol Enderlin
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd recommend using "-Dlog4j.debug" on the command line when you're working on setting that up so you can see how log4j is getting configured. If you're programmatically setting the system property you'll need to make sure the system property is set before log4j tries to use it, especially if you've got log4j.properties or log4j.xml in the classpath.
 
If you're gonna buy things, buy this thing and I get a fat kickback:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic