logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tom Quarendon" <t...@teamwpc.co.uk>
Subject RE: SIGSEGV on log4cxx initialisation
Date Fri, 27 Aug 2004 08:27:43 GMT
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@pirinsoft.com]
Sent: 27 August 2004 08:57
To: 'Log4CXX User'; tomq@teamwpc.co.uk
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@teamwpc.co.uk]
Sent: Thursday, August 26, 2004 15:05
To: log4cxx-user@logging.apache.org
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


Mime
View raw message