Hi all,
I am trying to understand what is so fundamentally wrong with the following
piece of code (taken from:
https://logging.apache.org/log4cxx/usage.html#Configuration).
If I compile it with (see attached file):
$ g++ -g -o logger log4cxx_crash.cpp -llog4cxx
Here is the crash I get [*]. I did check that this is a different crash
from the one explained in the FAQ:
https://logging.apache.org/log4cxx/faq.html
I've simply moved the initialisation from outside `main()` function to
inside `main()` function. I fail to understand why the order of
initialisation is so important (I could not find anything relevant in the
documentation).
Thanks for comments, my c++ knowledge would need a refresher.
Regards.
[*]
Using host libthread_db library "/lib64/libthread_db.so.1".
0 [0x7ffff7fb0780] INFO MyApp null - Entering application.
3 [0x7ffff7fb0780] INFO MyApp null - Exiting application.
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff5f69dc9 in apr_pool_create_ex () from /lib64/libapr-1.so.0
Missing separate debuginfos, use: debuginfo-install apr-1.5.1-3.fc21.x86_64
apr-util-1.5.4-1.fc21.x86_64 cyrus-sasl-lib-2.1.26-19.fc21.x86_64
expat-2.1.0-10.fc21.x86_64 libdb-5.3.28-9.fc21.x86_64
libgcc-4.9.2-6.fc21.x86_64 libstdc++-4.9.2-6.fc21.x86_64
libuuid-2.25.2-3.fc21.x86_64 log4cxx-0.10.0-17.fc21.x86_64
nspr-4.10.8-1.fc21.x86_64 nss-3.19.1-1.0.fc21.x86_64
nss-softokn-freebl-3.19.1-1.0.fc21.x86_64 nss-util-3.19.1-1.0.fc21.x86_64
openldap-2.4.40-3.fc21.x86_64 zlib-1.2.8-7.fc21.x86_64
(gdb) bt
#0 0x00007ffff5f69dc9 in apr_pool_create_ex () from /lib64/libapr-1.so.0
#1 0x00007ffff7b26b58 in log4cxx::helpers::Pool::Pool() () from
/lib64/liblog4cxx.so.10
#2 0x00007ffff7ae06ea in
log4cxx::helpers::MutexException::formatMessage(int) () from
/lib64/liblog4cxx.so.10
#3 0x00007ffff7ae0786 in
log4cxx::helpers::MutexException::MutexException(int) () from
/lib64/liblog4cxx.so.10
#4 0x00007ffff7b4a310 in
log4cxx::helpers::synchronized::synchronized(log4cxx::helpers::Mutex
const&) () from /lib64/liblog4cxx.so.10
#5 0x00007ffff7b5d9c8 in log4cxx::WriterAppender::close() () from
/lib64/liblog4cxx.so.10
#6 0x00007ffff7ac979c in log4cxx::ConsoleAppender::~ConsoleAppender() ()
from /lib64/liblog4cxx.so.10
#7 0x00007ffff7ac98b9 in log4cxx::ConsoleAppender::~ConsoleAppender() ()
from /lib64/liblog4cxx.so.10
#8 0x00007ffff7aba247 in
log4cxx::helpers::AppenderAttachableImpl::~AppenderAttachableImpl() () from
/lib64/liblog4cxx.so.10
#9 0x00007ffff7b0494c in log4cxx::Logger::~Logger() () from
/lib64/liblog4cxx.so.10
#10 0x00007ffff7b388b4 in log4cxx::spi::RootLogger::~RootLogger() () from
/lib64/liblog4cxx.so.10
#11 0x00007ffff7b0429a in log4cxx::Logger::~Logger() () from
/lib64/liblog4cxx.so.10
#12 0x00007ffff7b04429 in log4cxx::Logger::~Logger() () from
/lib64/liblog4cxx.so.10
#13 0x00000000004017c4 in
log4cxx::helpers::ObjectPtrT<log4cxx::Logger>::~ObjectPtrT (this=0x6031a0
<logger>, __in_chrg=<optimized out>) at
/usr/include/log4cxx/helpers/objectptr.h:100
#14 0x00007ffff6e38392 in __run_exit_handlers () from /lib64/libc.so.6
#15 0x00007ffff6e383e5 in exit () from /lib64/libc.so.6
#16 0x00007ffff6e1efe7 in __libc_start_main () from /lib64/libc.so.6
#17 0x0000000000401319 in _start ()
--
Mathieu
// include log4cxx header files.
#include <log4cxx/logger.h>
#include <log4cxx/basicconfigurator.h>
#include <log4cxx/helpers/exception.h>
#include <cstdlib>
using namespace log4cxx;
using namespace log4cxx::helpers;
LoggerPtr logger;
int main(int argc, char **argv)
{
int result = EXIT_SUCCESS;
logger=Logger::getLogger("MyApp");
try
{
// Set up a simple configuration that logs on the console.
BasicConfigurator::configure();
LOG4CXX_INFO(logger, "Entering application.");
LOG4CXX_INFO(logger, "Exiting application.");
}
catch(...)
{
result = EXIT_FAILURE;
}
return result;
}