logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rhys Ulerich <rhys.uler...@gmail.com>
Subject Re: Static destruction fiasco?
Date Sun, 27 Feb 2011 20:04:04 GMT
> I've noticed that this little test program segfaults beautifully under 0.10

The "logger = 0" fix from my last email of course assumes regular program exit.

In case anyone wants something a little cleaner, atexit() can save you when
your program unwinds for other reasons:


    #include <cstdlib>
    #include <log4cxx/logger.h>

    static log4cxx::LoggerPtr logger;

    static struct DestructLoggerRegistration {
        DestructLoggerRegistration() { atexit(&destruct_logger); }
        static void destruct_logger() { logger = 0; }
    } destructLoggerRegistration;

    int main()
    {
        logger = log4cxx::Logger::getLogger("someName");
        LOG4CXX_WARN(logger, "Stuffstuffstuff");
        return 0;
    }

where (at least for me) atexit() seems to make its callbacks prior to
static instance destruction occurs.

- Rhys

Mime
View raw message