Log4CXX hang
Hi, Thanks for reading this post. I have a C program running on CentOS 5.11, compiled through g++ calling a C++ library and this C++ library try to use log4cxx to do logging. However, when I initialize LoggerPtr Log4XXLogger::loggerMyMain(Logger::getLogger( "main")); as global variable, my program hang at startup and gdb stack is like #0 0xe405 in __kernel_vsyscall () #1 0x0067bcc5 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/libpthread.so.0 #2 0x0096b9cc in __cxa_guard_acquire () from /usr/lib/libstdc++.so.6 #3 0xf764fa0e in log4cxx::helpers::Transcoder::decode (src="70023", dst="Mutex exception: stat = ") at transcoder.cpp:247 #4 0xf763b7b1 in log4cxx::helpers::StringHelper::toString (n=70023, pool=..., s="Mutex exception: stat = ") at stringhelper.cpp:108 #5 0xf75c6644 in log4cxx::helpers::MutexException::formatMessage (stat=70023) at exception.cpp:228 #6 0xf75c66ef in log4cxx::helpers::MutexException::MutexException (this=0x866eb38, stat=70023) at exception.cpp:213 #7 0xf7600c4a in log4cxx::helpers::Mutex::Mutex (this=0x8666a30, p=...) at mutex.cpp:37 #8 0xf75a4e56 in LocaleCharsetDecoder () at charsetdecoder.cpp:360 #9 log4cxx::helpers::CharsetDecoder::createDefaultDecoder () at charsetdecoder.cpp:430 #10 0xf75a51b1 in log4cxx::helpers::CharsetDecoder::getDefaultDecoder () at charsetdecoder.cpp:435 #11 0xf764fb28 in log4cxx::helpers::Transcoder::decode (src="main", dst="") at transcoder.cpp:247 #12 0xf75f8bc8 in log4cxx::LogManager::getLogger (name="main") at logmanager.cpp:120 #13 0xf75f0812 in log4cxx::Logger::getLogger (name=0xf778f9a0 "main") at logger.cpp:496 #14 0xf778d769 in Log4CXXLoggerInner::Log4CXXLoggerInner (this=0xf7799ba8) at log4CXXLoggerInner.cpp:7 #15 0xf778d35d in __static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535) at log4XXLogger.cpp:4 #16 0xf778d399 in global constructors keyed to _ZN12Log4XXLogger10log4cInnerE() () at log4XXLogger.cpp:30 #17 0xf778dfc6 in __do_global_ctors_aux () from /mycompany/pkgs/linux/intel/packagename/packageversion/lib/libserver.so.2 #18 0xf776c10d in _init () from /mycompany/pkgs/linux/intel/packagename/packageversion/lib/libserver.so.2 #19 0x004fc493 in call_init () from /lib/ld-linux.so.2 #20 0x004fc5a3 in _dl_init_internal () from /lib/ld-linux.so.2 #21 0x004ee84f in _dl_start_user () from /lib/ld-linux.so.2 but if I make it as part of class, start the global variable as NULL and then new and assign as class A below class A { public: A() { string appPath = getenv("APPDIR"); appPath = appPath + "/" + LOG4CXX_CONFIG_FILE_NAME; // Load configuration file DOMConfigurator::configure(appPath.c_str()); m_serviceLogger = Logger::getLogger("tuxedoService"); } void log() { LOG4CXX_ERROR(m_serviceLogger, "This is a Test log"); } private: LoggerPtr m_serviceLogger; }; my log message is unpredictable, sometimes produce 0 line sometimes produces many lines. Can anybody tell me how to resolve this issue? thanks -- Sent from: http://apache-logging.6191.n7.nabble.com/Log4cxx-Users-f30946.html
Re: Log4CXX hang
Guten Tag chihhsiw, am Montag, 21. Mai 2018 um 11:37 schrieben Sie: > Thanks for reading this post. I have a C program running on CentOS 5.11, > compiled through g++ calling a C++ library and this C++ library try to use > log4cxx to do logging. You didn't tell which version of log4cxx you are using, it might be worth it to test with a current master. > However, when I initialize > LoggerPtr Log4XXLogger::loggerMyMain(Logger::getLogger( "main")); as global > variable, my program hang at startup and gdb stack is like How did you configure log4cxx before that call? Like with your class example at the bottom, you first need to configure and that retrieve a logger. > #0 0xe405 in __kernel_vsyscall () > #1 0x0067bcc5 in pthread_cond_wait@@GLIBC_2.3.2 () from > /lib/libpthread.so.0 > #2 0x0096b9cc in __cxa_guard_acquire () from /usr/lib/libstdc++.so.6 > #3 0xf764fa0e in log4cxx::helpers::Transcoder::decode (src="70023", > dst="Mutex exception: stat = ") at transcoder.cpp:247 This looks like two problems: First log4cxx is throwing some MutexException because it can't create a necessary mutex instance using APR. That shouldn't happen and is either related to how you use log4cxx, e.g. you didn't configure it it properly, or there might be something broken regarding APR, log4cxx and whatever. So I suggest to first look into why that exception gets thrown using some debugger, so that you don't rely on the string error message being created, but are able to see the return value of apr_thread_mutex_create. Have a look at the CTORs of "mutex.cpp", one of them is used and throwing the exception. The second problem seems to be that the CXA guard doesn't seem to be released ever for some reason. That shouldn't happen as well and might mean that you have some problems regarding multi-threading, some deadlock or such. That as well heavily depends on how you actually configure log4cxx and such. https://stackoverflow.com/questions/26013650/threadsafe-lazy-initialization-static-vs-stdcall-once-vs-double-checked-locki > but if I make it as part of class, start the global variable as NULL and > then new and assign as class A below [...] > my log message is unpredictable, sometimes produce 0 line sometimes produces > many lines. Maybe I'm missing something, but the configuration itself looks OK to me. Where and how do you create instances of class A? Your problem could again be related to multiple threads creating multiple instances of class A, configuring log4cxx multiple time. Mit freundlichen Grüßen, Thorsten Schöning -- Thorsten Schöning E-Mail: thorsten.schoen...@am-soft.de AM-SoFT IT-Systeme http://www.AM-SoFT.de/ Telefon...05151- 9468- 55 Fax...05151- 9468- 88 Mobil..0178-8 9468- 04 AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow