This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Other Open Source Projects and the fly likes specify log file name through java code using log4j Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "specify log file name through java code using log4j" Watch "specify log file name through java code using log4j" New topic
Author

specify log file name through java code using log4j

Prasad Shindikar
Ranch Hand

Joined: Feb 18, 2007
Posts: 114
Hi,

I want the filename for logging to be specified through code.

Please find my FileAppender module in the log4j.properties file.



In my Java code, I have done the following:


However, every time the log file is generated, the filename of the log file is 'default.log'. However, I want the filename to be 'mylog.log'.

Can anyone tell me how can I implement this thing ? The filename must come dynamically through code.

I have also tried using but it is always returning NULL.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Your log4j config file is probably overwriting what you set in your java class, try commenting out what you have in the config file


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Prasad Shindikar
Ranch Hand

Joined: Feb 18, 2007
Posts: 114
In that case, it does not take a file name.

It creates a log file with filename '.log', completely ignoring ${product.productid}

I think, since the log4j.properties is loaded initially, it takes the log file name to be default.log. That's acceptable.

But, if I change it in Java, it is not getting reflected, probably because the configuration needs to be refreshed somehow ?
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hmm, you might need to look at the Log4J API on how to do this, alternatively you could try passing in the -D option on the command line (and again comment out the log4j.properties)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: specify log file name through java code using log4j
 
Similar Threads
Log4j created file not able to delete while testing my application??
Log4j created file not able to delete while testing my application??
Date in filename of log4j
How can i add Log4j suppourt to my Application
Delete file when the file downloaded.