At 11:59 PM 12/13/2004, Barak Simon wrote:
Hi,
I have an interesting problem:

I have derived a customised logger, say, DBLogger from the log4cxx::Logger class, which is using a customised factory, say, DBFactory.
We have a thin layer on top of log4cxx with our own Logger class encapsulating the underlying log4cxx logger class, or in that case,
encapsulating the DBLogger extension class. We also have a LogManager of our own which handles our map of wrapper loggers by their names.


The Problem:
It seems that whenever a logger name is defined in a log4cxx configuration file, is actually being created dynamically by log4cxx using of course
the default factory rather than our own DBFactory class.
When we come to create this logger (i.e. when the user actually wants to log with the logger), though this logger is not in our own logmanager map at that stage
it is already in log4cxx::LogManager map, so we get back an already existing log4cxx::Logger, and effectively try to cast it into a customised DBLogger
(since we have a member of DBLogger inside each wrapper logger), which of course results with a zeroed pointer and a segmentation fault.


Now, I know that one can write <categoryFactory class="DBFactory"/> in the configuration file to tell log4cxx to use DBFactory for the loggers
it needs to create dynamically, but that puts too much responsibility on our users, which may get to a lot of trouble if they forgot to set it.
(even if we can robustly prevent the segmentation fault, we are enforced to use Logger instead of DBLogger in this case).

As Curt mentioned, if DBLogger is for Database logging, then using a DBAppender is probably much more appropriate than extending Logger.

Assuming DBLogger performs some other function which may not be
accomplished by the traditional extensions point (appender, layout),
then your questions are quite well put. In the log4j project, for the
reasons you mention, we avoid letting the user to specify her logger
factory at the level of a single logger. The user can specify a logger
factory at the level of the entire logger hierarchy with the help of a
custom repository selector. The repository selector return a specific
logger hierarchy and this hierarchy is responsible for creating loggers
of a given type.

The basic idea is explained here:

  http://www.qos.ch/logging/sc.jsp

I hope this helps,

Thanks,
Barak

--

-- Ceki G�lc�

The complete log4j manual: http://qos.ch/log4j/




Reply via email to