all should work now, but test mrwautofunctiontracelog4cxx_test-mt fails, so no multithreading until this is fixed; refs #2

master
Marc Wäckerlin 12 years ago
parent c5c8f82d05
commit c24a43ccb2
  1. 9
      configure.in
  2. 24
      src/autostacktracelog4cxx.cxx
  3. 83
      src/log4cxxconfiguration.cxx
  4. 16
      src/mrw/functiontrace.hxx
  5. 20
      test/functiontrace_test.cxx
  6. 4
      test/makefile.am
  7. 84
      test/mrwautofunctiontracelog4cxx_test.cxx

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

@ -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);
}

@ -26,6 +26,7 @@
#include <log4cxx/propertyconfigurator.h>
#include <log4cxx/helpers/properties.h>
#include <fstream>
#include <cstdlib>
#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);
}

@ -253,10 +253,10 @@ namespace mrw {
_tracer(tracer.begin(), tracer.end()) {
log4cxx::Logger* logger(log4cxx::Logger::getLogger(_tracer));
if (logger->isDebugEnabled()) {
std::basic_stringstream<log4cxx::String::value_type> oss;
std::basic_stringstream<std::string::value_type> oss;
oss<<std::hex<<std::setw(15)<<_addr<<": "
<<std::dec<<std::setw(2+_level)
<<std::setfill(log4cxx::String::value_type(' '))<<"\\ "<<_name;
<<std::setfill(std::string::value_type(' '))<<"\\ "<<_name;
logger->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<log4cxx::String::value_type> oss;
std::basic_stringstream<std::string::value_type> oss;
oss<<std::setw(17)<<' '
<<std::setw(2+_level)<<std::setfill(log4cxx::String::value_type(' '))
<<std::setw(2+_level)<<std::setfill(std::string::value_type(' '))
<<"\\ "<<_name;
logger->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<log4cxx::String::value_type> oss;
std::basic_stringstream<std::string::value_type> oss;
if (_addr)
oss<<std::hex<<std::setw(15)<<_addr<<": "<<std::dec;
else
oss<<std::setw(17)<<' ';
oss<<std::setw(2+_level)<<std::setfill(log4cxx::String::value_type(' '))
oss<<std::setw(2+_level)<<std::setfill(std::string::value_type(' '))
<<"/ "<<_name;
logger->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;
};

@ -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() {

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

@ -67,7 +67,7 @@ void anotherFunction() {
}
#ifdef _MT
#include <boost/thread/thread.hxx>
#include <boost/thread/thread.hpp>
//#include <unistd.h> // 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

Loading…
Cancel
Save