Just use the log4j.categoryFactory property. I use that myself for my
custom Category (that enables tracing) and it works fine.
-Jim Moore
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Monday, February 12, 2001 2:51 PM
To: [EMAIL PROTECTED]
Subject: Overriding the default "DefaultFactory"
Being able to call Category.getInstance("name", aFactory) is really nice,
I can subclass the Category class and add more log-like methods (and
putting them all in one convenient object, tied to a namespace is very
nice). For example, I can add a statistics counting method, such as
"count(int i) to the subclass and use a single object for logging and
statistics counting.
There is an inherit problem in this design...consider:
I configure log4j using a properties file and reference something like
the following (I can turn this on or off):
log4j.category.com.abc.xyz=debug, stdout
Before any of my code is called the log4j mechanism will have created an
entry named "com.abc.xyz" in its hashtable and created an object (which
WILL be a Category object) for this object. Subsequent access to the
object with name "com.abc.xyz" will return this instance (that was put
into the hashtable).
Somewhere in my constructor for this object I do:
SubclassOfCategory cat = (SubclassOf)Category.getInstance(classname,
myFactory);
where myFactory has a "makeNewCategoryInstance" method that returns a
subclass of Category (specifically, SubclassOfCategory).
The problem is that if I dont setup the statement in the log4j properties
file (or the watchlog property file) then this code works fine - the
first time the object named "com.abc.xyz" is referenced by category is
using MY category factory - and so my version of the object is put into
the hashtable.
But if I "turn on" the entry in the properties file, log4j gets "in
there" first and screws it up so that the getInstance method return a
Category object instead of the subclass SubclassOfCategory object and I
get a class cast exception.
So, can you tell me how to tell log4j to use a given factory as the
default. There must be a way...possibly a static method in
org.log4j.Hierarchy that allows me to set its default factory.
Any ideas? If so could you email me as well on [EMAIL PROTECTED] as I'm not
quite on the list yet.
Mike Papper
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]