From c24a43ccb294a2b9374ec316019a023c6512afa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=A4ckerlin?= Date: Fri, 6 Jul 2012 09:35:05 +0000 Subject: [PATCH] all should work now, but test mrwautofunctiontracelog4cxx_test-mt fails, so no multithreading until this is fixed; refs #2 --- configure.in | 9 +-- src/autostacktracelog4cxx.cxx | 24 +++---- src/log4cxxconfiguration.cxx | 83 +++++++++++----------- src/mrw/functiontrace.hxx | 16 ++--- test/functiontrace_test.cxx | 20 +++--- test/makefile.am | 4 +- test/mrwautofunctiontracelog4cxx_test.cxx | 84 +++++++++++------------ 7 files changed, 121 insertions(+), 119 deletions(-) diff --git a/configure.in b/configure.in index 09f2c3b..da7d841 100644 --- a/configure.in +++ b/configure.in @@ -68,7 +68,7 @@ AX_DEFINE_DIR([DATADIR], [datadir]) #AC_SUBST(DATADIR) # macros -sed 's/.*/ &/g' ${0%/*}/README > ${0%/*}/README.debian +sed -e 's/^$/./' -e 's/^/ /g' ${0%/*}/README > ${0%/*}/README.debian READMEDEB=README.debian AC_SUBST_FILE(READMEDEB) README=README @@ -143,7 +143,7 @@ AC_ARG_ENABLE(ltdl, Note: For automated stack trace, you need either ltdl or the libbfd BFD library from the binutils package at compile time.], - [have_ltdl="$enableval"], [have_ltdl="yes"]) + [have_ltdl="$enableval"], [have_ltdl="$have_ltdl"]) AM_CONDITIONAL(HAVE_LTDL, test "$have_ltdl" = "yes") AC_ARG_ENABLE(dynamicstack, [ --enable-dynamic-stack enable use of libtool library dynamic loading @@ -192,12 +192,13 @@ if test "$have_stacktrace" = "yes"; then if test "$have_dynamicstack" != "yes"; then AC_DEFINE([NO_LTDL]) AC_SEARCH_LIBS(bfd_openr, bfd, - [AC_MSG_RESULT([OK, found libbfd])], + [AC_MSG_RESULT([OK, found libbfd])], [AC_MSG_ERROR([BFD library from the binutils package not found! It is required for stack trace! - install binutils or binutils-devel - or configure with option --enable-ltdl - - or configure with option --disable-stacktrace])]) + - or configure with option --disable-stacktrace])], + -lz) fi # bug { ac_includes_default=$old_ac_includes_default diff --git a/src/autostacktracelog4cxx.cxx b/src/autostacktracelog4cxx.cxx index 4aa4ddd..ba8b519 100644 --- a/src/autostacktracelog4cxx.cxx +++ b/src/autostacktracelog4cxx.cxx @@ -92,9 +92,9 @@ namespace mrw { void unexpected_log4cxx() { static const std::string name("mrw.stacktrace"); log4cxx::LoggerPtr logger - (log4cxx::Logger::getLogger(log4cxx::String(name.begin(), name.end()))); + (log4cxx::Logger::getLogger(std::string(name.begin(), name.end()))); static const std::string txt("Unexpected Exception"); - logger->fatal(log4cxx::String(txt.begin(), txt.end()), MRW_LOG4CXX_LOCATION); + logger->fatal(std::string(txt.begin(), txt.end()), MRW_LOG4CXX_LOCATION); StackTrace::createSymtable(); std::string st((std::string)StackTrace()); try { @@ -102,15 +102,15 @@ namespace mrw { } catch (const mrw::exception& x) { std::string txt(std::string("Reason:\n")+x.what() +"\nStack:\n"+x.stacktrace()); - logger->fatal(log4cxx::String(txt.begin(), txt.end())); + logger->fatal(std::string(txt.begin(), txt.end())); } catch (const std::exception& x) { std::string txt(std::string("Reason:\n")+x.what() +"\nStack:\n"+st); - logger->fatal(log4cxx::String(txt.begin(), txt.end())); + logger->fatal(std::string(txt.begin(), txt.end())); } catch (...) { std::string txt(std::string("Reason: **** not available ****") +"\nStack:\n"+st); - logger->fatal(log4cxx::String(txt.begin(), txt.end())); + logger->fatal(std::string(txt.begin(), txt.end())); } throw std::bad_exception(); } @@ -148,9 +148,9 @@ namespace mrw { void terminate_log4cxx() { static const std::string name("mrw.stacktrace"); log4cxx::LoggerPtr logger - (log4cxx::Logger::getLogger(log4cxx::String(name.begin(), name.end()))); + (log4cxx::Logger::getLogger(std::string(name.begin(), name.end()))); static const std::string txt("Uncaught Exception"); - logger->fatal(log4cxx::String(txt.begin(), txt.end()), MRW_LOG4CXX_LOCATION); + logger->fatal(std::string(txt.begin(), txt.end()), MRW_LOG4CXX_LOCATION); StackTrace::createSymtable(); std::string st((std::string)StackTrace()); try { @@ -158,15 +158,15 @@ namespace mrw { } catch (const mrw::exception& x) { std::string txt(std::string("Reason:\n")+x.what() +"\nStack:\n"+x.stacktrace()); - logger->fatal(log4cxx::String(txt.begin(), txt.end())); + logger->fatal(std::string(txt.begin(), txt.end())); } catch (const std::exception& x) { std::string txt(std::string("Reason:\n")+x.what() +"\nStack:\n"+st); - logger->fatal(log4cxx::String(txt.begin(), txt.end())); + logger->fatal(std::string(txt.begin(), txt.end())); } catch (...) { std::string txt(std::string("Reason: **** not available ****") +"\nStack:\n"+st); - logger->fatal(log4cxx::String(txt.begin(), txt.end())); + logger->fatal(std::string(txt.begin(), txt.end())); } exit(1); } @@ -222,9 +222,9 @@ namespace mrw { std::string st((std::string)StackTrace()); static const std::string name("mrw.stacktrace"); log4cxx::LoggerPtr logger - (log4cxx::Logger::getLogger(log4cxx::String(name.begin(), name.end()))); + (log4cxx::Logger::getLogger(std::string(name.begin(), name.end()))); std::string errtxt("Aborted by signal: "+txt+"\nStack:\n"+st); - logger->fatal(log4cxx::String(errtxt.begin(), errtxt.end())); + logger->fatal(std::string(errtxt.begin(), errtxt.end())); if (abort) exit(1); } diff --git a/src/log4cxxconfiguration.cxx b/src/log4cxxconfiguration.cxx index 102d08e..428d3c6 100644 --- a/src/log4cxxconfiguration.cxx +++ b/src/log4cxxconfiguration.cxx @@ -26,6 +26,7 @@ #include #include #include +#include #if (__GNUC__==3 && __GNUC_MINOR__<4 || __GNUC__<3) \ && defined(_REENTRANT) && !defined(_MT) @@ -125,93 +126,93 @@ log4j.appender.A1.layout.ConversionPattern = \%-40l - \%m\%n logconfigfile = "/etc/mrwlog4cxx"; if (logconfigfile.size()) { log4cxx::PropertyConfigurator::configure - (log4cxx::String(logconfigfile.begin(), logconfigfile.end())); + (std::string(logconfigfile.begin(), logconfigfile.end())); return; } log4cxx::helpers::Properties properties; std::string name, cont; properties.setProperty((name="log4j.rootLogger", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="WARN, A1", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.logger.mrw.fntracea", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="OFF", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.logger.mrw.fn", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="OFF", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.logger.mrw.fn.log4cxx", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="OFF", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.logger.mrw.fn.boost", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="OFF", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.logger.mrw.fn.Thread", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="OFF", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.logger.mrw.fn.QString", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="OFF", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.logger.mrw.fn.QShared", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="OFF", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.logger.mrw.fn.QWidget", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="OFF", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.logger.mrw.fn.QRect", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="OFF", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.logger.mrw.fn.qstrcmp", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="OFF", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.logger.mrw.fn.*.qt_cast", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="OFF", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.logger.mrw.fn.mrw", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="OFF", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.logger.mrw.fn.std", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="OFF", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.logger.mrw.fn.CppUnit", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="OFF", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.logger.mrw.fn.__gnu_cxx", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="OFF", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.appender.A1", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="org.apache.log4j.ConsoleAppender", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.appender.A1.layout", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="org.apache.log4j.PatternLayout", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); #ifdef _MT properties.setProperty((name="log4j.appender.A1.layout.ConversionPattern", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="%t-%-40l - %m%n", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); #else properties.setProperty((name="log4j.appender.A1.layout.ConversionPattern", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="%-40l - %m%n", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); #endif log4cxx::PropertyConfigurator::configure(properties); } diff --git a/src/mrw/functiontrace.hxx b/src/mrw/functiontrace.hxx index 3f54a9d..d1dfe5b 100644 --- a/src/mrw/functiontrace.hxx +++ b/src/mrw/functiontrace.hxx @@ -253,10 +253,10 @@ namespace mrw { _tracer(tracer.begin(), tracer.end()) { log4cxx::Logger* logger(log4cxx::Logger::getLogger(_tracer)); if (logger->isDebugEnabled()) { - std::basic_stringstream oss; + std::basic_stringstream oss; oss<forcedLog(MRW_LEVEL_DEBUG, oss.str(), MRW_LOG4CXX_LOCATION); ++_level; @@ -269,9 +269,9 @@ namespace mrw { _tracer(tracer.begin(), tracer.end()) { log4cxx::Logger* logger(log4cxx::Logger::getLogger(_tracer)); if (logger->isDebugEnabled()) { - std::basic_stringstream oss; + std::basic_stringstream oss; oss<forcedLog(MRW_LEVEL_DEBUG, oss.str(), MRW_LOG4CXX_LOCATION); @@ -282,12 +282,12 @@ namespace mrw { log4cxx::Logger* logger(log4cxx::Logger::getLogger(_tracer)); if (logger->isDebugEnabled()) { --_level; - std::basic_stringstream oss; + std::basic_stringstream oss; if (_addr) oss<forcedLog(MRW_LEVEL_DEBUG, oss.str(), MRW_LOG4CXX_LOCATION); @@ -295,10 +295,10 @@ namespace mrw { } private: const void* _addr; - const log4cxx::String _name; + const std::string _name; const std::string _file; unsigned long _line; - const log4cxx::String _tracer; + const std::string _tracer; /** @todo for multithreading, use thread specific storage */ static unsigned int _level; }; diff --git a/test/functiontrace_test.cxx b/test/functiontrace_test.cxx index 255ba3d..6d471d6 100644 --- a/test/functiontrace_test.cxx +++ b/test/functiontrace_test.cxx @@ -74,25 +74,25 @@ class FunctionTraceTest: public CppUnit::TestFixture { log4cxx::helpers::Properties properties; std::string name, cont; properties.setProperty((name="log4j.rootLogger", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="DEBUG, A1", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.appender.A1", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="org.apache.log4j.FileAppender", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.appender.A1.layout", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="org.apache.log4j.PatternLayout", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.appender.A1.layout.ConversionPattern", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="%F:%L - %m%n", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.appender.A1.filename", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="functiontrace_test.log", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); log4cxx::PropertyConfigurator::configure(properties); } void Calls() { diff --git a/test/makefile.am b/test/makefile.am index c9b7d29..036146a 100644 --- a/test/makefile.am +++ b/test/makefile.am @@ -156,7 +156,7 @@ if AUTOFNTRACE mrwautofunctiontracelog4cxx_test_LDFLAGS = \ @CPPUNIT_LIBS@ -L${top_builddir}/src -finstrument-functions mrwautofunctiontracelog4cxx_test_LDADD = \ - -llog4cxx -lmrwautofunctiontracelog4cxx + -llog4cxx -lmrwautofunctiontracelog4cxx -lmrw if HAVE_THREADS if HAVE_BOOST_THREAD mrwautofunctiontracelog4cxx_test_mt_SOURCES = \ @@ -168,7 +168,7 @@ if HAVE_BOOST_THREAD mrwautofunctiontracelog4cxx_test_mt_LDFLAGS = \ @CPPUNIT_LIBS@ -L${top_builddir}/src @THREADS@ -finstrument-functions mrwautofunctiontracelog4cxx_test_mt_LDADD = \ - -llog4cxx -lmrwautofunctiontracelog4cxx-mt @BOOST_THREAD_LIB@ + -llog4cxx -lmrwautofunctiontracelog4cxx-mt -lmrw @BOOST_THREAD_LIB@ endif endif endif diff --git a/test/mrwautofunctiontracelog4cxx_test.cxx b/test/mrwautofunctiontracelog4cxx_test.cxx index 3e08db2..661ff05 100644 --- a/test/mrwautofunctiontracelog4cxx_test.cxx +++ b/test/mrwautofunctiontracelog4cxx_test.cxx @@ -67,7 +67,7 @@ void anotherFunction() { } #ifdef _MT -#include +#include //#include // sleep, the one from boost::thread does not work! class Thread { public: @@ -91,91 +91,91 @@ namespace mrw { log4cxx::helpers::Properties properties; std::string name, cont; properties.setProperty((name="log4j.rootLogger", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="OFF, A1", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.logger.mrw.fn", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="DEBUG", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.logger.mrw.fn.global", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="OFF", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.logger.mrw.fn.allocator", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="OFF", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.logger.mrw.fn.std.*", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="OFF", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.logger.mrw.fn.log4cxx", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="OFF", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.logger.mrw.fn.boost", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="OFF", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.logger.mrw.fn.Thread", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="OFF", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.logger.mrw.fn.mrw", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="OFF", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.logger.mrw.fn.std", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="OFF", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.logger.mrw.fn.new", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="OFF", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.logger.mrw.fn.CppUnit", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="OFF", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.logger.mrw.fn.__gnu_cxx", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="OFF", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.appender.A1", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="org.apache.log4j.FileAppender", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.appender.A1.layout", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="org.apache.log4j.PatternLayout", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); #ifdef _MT properties.setProperty((name="log4j.appender.A1.layout.ConversionPattern", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="%t-%-27c%m%n", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.appender.A1.filename", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="mrwautofunctiontracelog4cxx_test-mt.log", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); #else properties.setProperty((name="log4j.appender.A1.layout.ConversionPattern", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="%-27c%m%n", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); properties.setProperty((name="log4j.appender.A1.filename", - log4cxx::String(name.begin(), name.end())), + std::string(name.begin(), name.end())), (cont="mrwautofunctiontracelog4cxx_test.log", - log4cxx::String(cont.begin(), cont.end()))); + std::string(cont.begin(), cont.end()))); #endif log4cxx::PropertyConfigurator::configure(properties); #ifdef _MT // sleep(4); // to be reproducable, wait for "main" flag Thread threadFunction; - boost::thread::thread thread1(threadFunction); - boost::thread::thread thread2(threadFunction); - boost::thread::thread thread3(threadFunction); + boost::thread thread1(threadFunction); + boost::thread thread2(threadFunction); + boost::thread thread3(threadFunction); #endif anotherFunction(); #ifdef _MT