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 09:49:27 GMT
I suspect that is it not that you must call some kind of configure before
you call getLogger(), but rather that the static initialisation in log4cxx
must happen before you call getLogger().

-----Original Message-----
From: Stoyan Damov [mailto:stoyan@pirinsoft.com]
Sent: 27 August 2004 10:38
To: 'Log4CXX User'
Subject: RE: SIGSEGV on log4cxx initialisation


>> If "getLogger" must not be called without prior "configure", it should
either check for itself if "configure" needs to be run.
I don't think so. Should the socket() function call WSAStartup if you forgot
to call it? Should every other Winsock function check whether WSAStartup was
called before that? The problem is not that getLogger() depends on
configure(), but that it is not clearly documented that you should call
configure() prior to calling getLogger() (if it's not clearly documented).

Cheers,
Stoyan

-----Original Message-----
From: Sven A.Schmidt [mailto:sas@abstracture.de]
Sent: Friday, August 27, 2004 11:52
To: Log4CXX User
Subject: Re: SIGSEGV on log4cxx initialisation

When I reported this problem a few days ago ("Re: Building on Mac OS/X
10.3") I thought this was a platform specific problem... This doesn't seem
to be the case after all. Even the included example "delayedloop"
relies on static initialization (like in your "fred") and crashes right
away.

IMHO, fiddling with different initialization in the user code is fixing the
problem at the wrong end... If "getLogger" must not be called without prior
"configure", it should either check for itself if "configure" needs to be
run.

Cheers,
Sven

On 27.08.2004, at 10:27, Tom Quarendon wrote:

> 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
>
>

---
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