|
|
Sponsor |
RE: SIGSEGV on log4cxx initialisation: msg#00043apache.logging.log4cxx.user
Right. So to make log4cxx work properly across multiple DLLs with all my C++ classes having static LoggerPtr objects I need to indulge in some serious use of the GCC "init_priority" attribute to control initialisation order. Surely there is a recognised way of going this -- doesn't everyone have static LoggerPtr objects in their classes? All my classes are like : fred.hpp ======== class Fred { static log4cxx::LoggerPtr logger; ... }; fred.cpp ======== log4cxx::LoggerPtr Fred::logger = log4cxx::Logger::getLogger("fred"); >From what you are saying, in order for this to work properly I need to make sure that the static initialisation of logger in fred.cpp is done after any static initialisation in the log4cxx DLL. Maybe the way to do it is fred.hpp ======== class Fred { static log4cxx::LoggerPtr logger_; ... }; fred.cpp ======== log4cxx::LoggerPtr Fred::logger_; log4cxx::LoggerPtr Fred::logger() { if (!logger_.get()) { logger_ = log4cxx::Logger::getLogger("fred"); } return logger_; } and use calls to logger() instead of references to the logger member. Is there a recommended way of doing this kind of stuff? Many thanks -----Original Message----- From: Stoyan Damov [mailto:stoyan@xxxxxxxxxxxxx] Sent: 27 August 2004 08:57 To: 'Log4CXX User'; tomq@xxxxxxxxxxxxx Subject: RE: SIGSEGV on log4cxx initialisation Welcome to order of initialization hell :) Try this instead: #include <log4cxx/Logger.h> #include <log4cxx/basicconfigurator.h> using namespace log4cxx; LoggerPtr GetLogger() { static LoggerPtr logger = Logger::getLogger("a.b"); return logger; } int main(int argc, char* argv[]) { BasicConfigurator::configure(); GetLogger()->fatal("Fatal message"); } HTH, Stoyan -----Original Message----- From: Tom Quarendon [mailto:tomq@xxxxxxxxxxxxx] Sent: Thursday, August 26, 2004 15:05 To: log4cxx-user@xxxxxxxxxxxxxxxxxx Subject: SIGSEGV on log4cxx initialisation Unless I've called some kind of configuration before I call Logger::getLogger, I seem to get a SIGSEGV. Program continues and works as expected, it is just an anoyance in a debugger where you get a SIGSEGV before you get to main. Indeed it's taken me quite a long time to realise that the segv is caused by log4cxx, and to realise that if you just continue and ignore it the program works fine. The sample program I'm using is #include <log4cxx/Logger.h> #include <log4cxx/basicconfigurator.h> using namespace log4cxx; LoggerPtr logger = Logger::getLogger("a.b"); int main(int argc, char* argv[]) { BasicConfigurator::configure(); logger->fatal("Fatal message"); } I'm on Windows XP and using Cygwin GCC, and running this through gdb I get 2 segvs before I get to main. I've just noticed that if I change it to move the "LoggerPtr logger = ..." line after the BasicConfigurator::configure() call I get the same 2 segvs, but this time when stepping over the BasicConfigurator::configure call. I'm not sure how to compile the log4cxx code with debug, so at the moment I can't give any help on where these segvx are comming from. --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.737 / Virus Database: 491 - Release Date: 11/08/2004 --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.737 / Virus Database: 491 - Release Date: 11/08/2004 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.737 / Virus Database: 491 - Release Date: 11/08/2004
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | RE: SIGSEGV on log4cxx initialisation, Stoyan Damov |
|---|---|
| Next by Date: | Re: SIGSEGV on log4cxx initialisation, Sven A . Schmidt |
| Previous by Thread: | RE: SIGSEGV on log4cxx initialisation, Stoyan Damov |
| Next by Thread: | Re: SIGSEGV on log4cxx initialisation, Sven A . Schmidt |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
Free MagazinesCisco NewsReceive 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 |
Home | sitemap
| advertise | OSDir is
an inevitable website.
|