Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Enable/Disable logging programatically

  Asked By: Annie    Date: Dec 27    Category: Java    Views: 1432
  

I want to configure Log4J or J2SE 1.4 logging programmatically. I
don't want to use any configuration files for configuring Log4J /J2SE
1.4 logging . I want to enable/disable logging facility at runtime
from my program. Sometime I may require to turn on only DEBUG,
sometimes DEBUG and INFO may be required. How can I do that? Please
help me. Any help would be much valuable.

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Phoebe Brown     Answered On: Dec 27

I think you need to make a wrapper around your logger. Log4j maybe let you to programatically  enable/disable logging, but by creating a wrapper you can handle your future requiremnets(that now you can't see them) better and easily.
I refer you to the chapter 17 of The J2EE Architect's Handbook written by Derek C. Ashmore for writing a wrapper around your logger. You can find the PDF version of this book from the www.theserverside.com .

 
Answer #2    Answered By: Latoya Murray     Answered On: Dec 27

you have to command your program  to do so, and if you don't want to use a config file, you might be able to facilitate an IPC mechanism, so a client or commander program command the logger to change its behaviour.

provide an interface within the main application (that uses log4j) and let an admin tool to communicate with it over that interface to modify the debugging level of the main app.

unless log4j has some built-in facility, the above could be a solution. maybe dig into apache log4j document / mailing list for more info

 
Didn't find what you were looking for? Find more on Enable/Disable logging programatically Or get search suggestion and latest updates.