Please take our Survey
logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

Re: Customised Loggers - an interesting and difficult problem: msg#00056

apache.logging.log4cxx.user

Subject: Re: Customised Loggers - an interesting and difficult problem

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/




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
version-control...    qnx.openqnx.dev...    redhat.rhn.user...    ietf.openpgp/20...    mail.mutt.user/...    web.microformat...    java.sync4j.use...    education.ezpro...    user-groups.blu...    solaris.manager...    org.fitug.debat...    technology.erps...    politics.activi...    linux.redhat.fe...    bug-tracking.ma...    xfce.user/2004-...    hams/2004-11/ms...    kde.users.pim/2...    culture.cooking...    freebsd.devel.x...    gnu.m4.adhoc/20...    ngpt.user/2002-...    apple.fink.deve...   
Home | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation