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 "MCMURTRIE, Dion" <Di...@suncorpmetway.com.au> on 2001/08/30 07:37:27 UTC

Changing logging priorities at run time

I working on a project that uses Log4J and would like to have some control
over changing the logging priority at run time.  From the API I can see that
I can change -
	* the root category priority
	* individual category's priority
	* the Hierarchy "disable" priority

I have made a small (test) jsp that allows configuration of the root
category, the hierarchy "disable" priority and all of the categories that
currently exist on our app server and it seems to work very well.  By having
a look through the code I can see that these three things will have a
slightly different effect and allow good flexibility in the produced log
messages.  But...

I have one particular concern at the moment about what I have done, and that
is what happens to log messages that are in the process of being logged when
I change the logging priority any of the three listed ways?  ie is this
thread safe, or will it have some unexpected/undesirable results?  I'm a bit
too scared to try this in production until I can figure out if this is a
safe operation.

To that end, am I going about dynamically configuring Log4J the right way?
We use the PropertyConfigurator in a server startup class to configure Log4J
at server start, but I am trying to tweak the logging priority at run time
to analyse problems when they occur.  Basically the code that I have gets an
instance of Category on the app server, gets the Hierarchy using
getHierarchy() then shows all the categories and their priority in a drop
box using getCurrentCategories().  I also get the root category using
getRoot() to display and allow setting of the root category priority.
Basically to set the priority of the individual categories and the root I
use the setPriority() method on the relevant Category object.  I also allow
setting of the hierarchy disable priority using hierarchy.disable(...) and
hierarchy.enableAll().

Is that the right way to go about it?  Is it a valid way to go about it (it
seems to achieve what I want it to)?  And is it thread safe - ie what is
going to happen to log messages that occur before, during and just after the
priority being set?

Finally, our categories for logging are named by the fully qualified class
names of the classes they are in.  From reading the documentation I would
assume that there is inheritance going on for priorities in the hierarchy,
but I don't seem to be able to get it to work. For example if I had a class
called au.com.sml.FooBar and it's priority was null, then if I set
au.com.sml to priority INFO I would expect that to be inherited by FooBar
but it doesn't seem to be.  What am I doing wrong that is stopping the
inheritance of priority?  Is there an easy way for me to get a graphical
representation of the category hierarchy that has been created by Log4J?

Much thanks in advance,
Dion.

------------------------------------------------------------

The contents of this message are the views of the Author and
do not necessarily reflect the views of SUNCORP METWAY LTD.
ABN 66 010 831 722

http://www.suncorpmetway.com.au


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org