You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by David Thielen <da...@thielen.com> on 2002/03/14 00:42:45 UTC
Turning off my logging programmatically
Hi all;
I have a library that I ship to people as a jar. Here is what I would like to be able to do:
1) If they have a given property set, I use the value of that property as my log4j configuration properties and do a configure with that. Works great.
2) However, if they give me no file, I want to disable all logging from my library without effecting their code. That means if they are using log4j, I don't effect their settings in any way AND I do no logging. If they don't use log4j, then I want nothing to happen - no logging of any kind. I tried the following but it dodn't work:
PropertyConfigurator.configure ();
Hierarchy h = new Hierarchy( Category.getInstance ( "net.windward" )); // all my code is net.windward.*****
h.disableAll();
Any ideas?
thanks - dave
Re: Turning off my logging programmatically
Posted by Ceki Gülcü <ce...@qos.ch>.
Have you tried the following?
(in log4j 1.1.x or log4j 1.2)
if(!condition) {
Category cat = Category.getInstance("net.winward");
cat.setPriority(Priority.FATAL);
}
(in log4j 1.2 only)
if(!condition) {
Logger logger = Logger.getLogger("net.winward");
logger.setLogger(Level.OFF);
}
Hope this helps, Ceki
At 16:42 13.03.2002 -0700, you wrote:
>Hi all;
>
>I have a library that I ship to people as a jar. Here is what I would like
>to be able to do:
>
>1) If they have a given property set, I use the value of that property as
>my log4j configuration properties and do a configure with that. Works great.
>
>2) However, if they give me no file, I want to disable all logging from my
>library without effecting their code. That means if they are using log4j,
>I don't effect their settings in any way AND I do no logging. If they
>don't use log4j, then I want nothing to happen - no logging of any kind. I
>tried the following but it dodn't work:
>
> PropertyConfigurator.configure ();
> Hierarchy h = new Hierarchy( Category.getInstance ( "net.windward" ));
> // all my code is net.windward.*****
> h.disableAll();
>
>Any ideas?
>
>thanks - dave
--
Ceki
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>