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) #AC_SUBST(DATADIR)
# macros # macros
sed 's/.*/ &/g' ${0%/*}/README > ${0%/*}/README.debian sed -e 's/^$/./' -e 's/^/ /g' ${0%/*}/README > ${0%/*}/README.debian
READMEDEB=README.debian READMEDEB=README.debian
AC_SUBST_FILE(READMEDEB) AC_SUBST_FILE(READMEDEB)
README=README README=README
@ -143,7 +143,7 @@ AC_ARG_ENABLE(ltdl,
Note: For automated stack trace, you need either Note: For automated stack trace, you need either
ltdl or the libbfd BFD library from ltdl or the libbfd BFD library from
the binutils package at compile time.], 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") AM_CONDITIONAL(HAVE_LTDL, test "$have_ltdl" = "yes")
AC_ARG_ENABLE(dynamicstack, AC_ARG_ENABLE(dynamicstack,
[ --enable-dynamic-stack enable use of libtool library dynamic loading [ --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 if test "$have_dynamicstack" != "yes"; then
AC_DEFINE([NO_LTDL]) AC_DEFINE([NO_LTDL])
AC_SEARCH_LIBS(bfd_openr, bfd, 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! [AC_MSG_ERROR([BFD library from the binutils package not found!
It is required for stack trace! It is required for stack trace!
- install binutils or binutils-devel - install binutils or binutils-devel
- or configure with option --enable-ltdl - or configure with option --enable-ltdl
- or configure with option --disable-stacktrace])]) - or configure with option --disable-stacktrace])],
-lz)
fi fi
# bug { # bug {
ac_includes_default=$old_ac_includes_default ac_includes_default=$old_ac_includes_default

@ -92,9 +92,9 @@ namespace mrw {
void unexpected_log4cxx() { void unexpected_log4cxx() {
static const std::string name("mrw.stacktrace"); static const std::string name("mrw.stacktrace");
log4cxx::LoggerPtr logger 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"); 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(); StackTrace::createSymtable();
std::string st((std::string)StackTrace()); std::string st((std::string)StackTrace());
try { try {
@ -102,15 +102,15 @@ namespace mrw {
} catch (const mrw::exception& x) { } catch (const mrw::exception& x) {
std::string txt(std::string("Reason:\n")+x.what() std::string txt(std::string("Reason:\n")+x.what()
+"\nStack:\n"+x.stacktrace()); +"\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) { } catch (const std::exception& x) {
std::string txt(std::string("Reason:\n")+x.what() std::string txt(std::string("Reason:\n")+x.what()
+"\nStack:\n"+st); +"\nStack:\n"+st);
logger->fatal(log4cxx::String(txt.begin(), txt.end())); logger->fatal(std::string(txt.begin(), txt.end()));
} catch (...) { } catch (...) {
std::string txt(std::string("Reason: **** not available ****") std::string txt(std::string("Reason: **** not available ****")
+"\nStack:\n"+st); +"\nStack:\n"+st);
logger->fatal(log4cxx::String(txt.begin(), txt.end())); logger->fatal(std::string(txt.begin(), txt.end()));
} }
throw std::bad_exception(); throw std::bad_exception();
} }
@ -148,9 +148,9 @@ namespace mrw {
void terminate_log4cxx() { void terminate_log4cxx() {
static const std::string name("mrw.stacktrace"); static const std::string name("mrw.stacktrace");
log4cxx::LoggerPtr logger 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"); 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(); StackTrace::createSymtable();
std::string st((std::string)StackTrace()); std::string st((std::string)StackTrace());
try { try {
@ -158,15 +158,15 @@ namespace mrw {
} catch (const mrw::exception& x) { } catch (const mrw::exception& x) {
std::string txt(std::string("Reason:\n")+x.what() std::string txt(std::string("Reason:\n")+x.what()
+"\nStack:\n"+x.stacktrace()); +"\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) { } catch (const std::exception& x) {
std::string txt(std::string("Reason:\n")+x.what() std::string txt(std::string("Reason:\n")+x.what()
+"\nStack:\n"+st); +"\nStack:\n"+st);
logger->fatal(log4cxx::String(txt.begin(), txt.end())); logger->fatal(std::string(txt.begin(), txt.end()));
} catch (...) { } catch (...) {
std::string txt(std::string("Reason: **** not available ****") std::string txt(std::string("Reason: **** not available ****")
+"\nStack:\n"+st); +"\nStack:\n"+st);
logger->fatal(log4cxx::String(txt.begin(), txt.end())); logger->fatal(std::string(txt.begin(), txt.end()));
} }
exit(1); exit(1);
} }
@ -222,9 +222,9 @@ namespace mrw {
std::string st((std::string)StackTrace()); std::string st((std::string)StackTrace());
static const std::string name("mrw.stacktrace"); static const std::string name("mrw.stacktrace");
log4cxx::LoggerPtr logger 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); 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); if (abort) exit(1);
} }

@ -26,6 +26,7 @@
#include <log4cxx/propertyconfigurator.h> #include <log4cxx/propertyconfigurator.h>
#include <log4cxx/helpers/properties.h> #include <log4cxx/helpers/properties.h>
#include <fstream> #include <fstream>
#include <cstdlib>
#if (__GNUC__==3 && __GNUC_MINOR__<4 || __GNUC__<3) \ #if (__GNUC__==3 && __GNUC_MINOR__<4 || __GNUC__<3) \
&& defined(_REENTRANT) && !defined(_MT) && defined(_REENTRANT) && !defined(_MT)
@ -125,93 +126,93 @@ log4j.appender.A1.layout.ConversionPattern = \%-40l - \%m\%n
logconfigfile = "/etc/mrwlog4cxx"; logconfigfile = "/etc/mrwlog4cxx";
if (logconfigfile.size()) { if (logconfigfile.size()) {
log4cxx::PropertyConfigurator::configure log4cxx::PropertyConfigurator::configure
(log4cxx::String(logconfigfile.begin(), logconfigfile.end())); (std::string(logconfigfile.begin(), logconfigfile.end()));
return; return;
} }
log4cxx::helpers::Properties properties; log4cxx::helpers::Properties properties;
std::string name, cont; std::string name, cont;
properties.setProperty((name="log4j.rootLogger", properties.setProperty((name="log4j.rootLogger",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="WARN, A1", (cont="WARN, A1",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.logger.mrw.fntracea", properties.setProperty((name="log4j.logger.mrw.fntracea",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="OFF", (cont="OFF",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.logger.mrw.fn", properties.setProperty((name="log4j.logger.mrw.fn",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="OFF", (cont="OFF",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.logger.mrw.fn.log4cxx", properties.setProperty((name="log4j.logger.mrw.fn.log4cxx",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="OFF", (cont="OFF",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.logger.mrw.fn.boost", properties.setProperty((name="log4j.logger.mrw.fn.boost",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="OFF", (cont="OFF",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.logger.mrw.fn.Thread", properties.setProperty((name="log4j.logger.mrw.fn.Thread",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="OFF", (cont="OFF",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.logger.mrw.fn.QString", properties.setProperty((name="log4j.logger.mrw.fn.QString",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="OFF", (cont="OFF",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.logger.mrw.fn.QShared", properties.setProperty((name="log4j.logger.mrw.fn.QShared",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="OFF", (cont="OFF",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.logger.mrw.fn.QWidget", properties.setProperty((name="log4j.logger.mrw.fn.QWidget",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="OFF", (cont="OFF",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.logger.mrw.fn.QRect", properties.setProperty((name="log4j.logger.mrw.fn.QRect",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="OFF", (cont="OFF",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.logger.mrw.fn.qstrcmp", properties.setProperty((name="log4j.logger.mrw.fn.qstrcmp",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="OFF", (cont="OFF",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.logger.mrw.fn.*.qt_cast", properties.setProperty((name="log4j.logger.mrw.fn.*.qt_cast",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="OFF", (cont="OFF",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.logger.mrw.fn.mrw", properties.setProperty((name="log4j.logger.mrw.fn.mrw",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="OFF", (cont="OFF",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.logger.mrw.fn.std", properties.setProperty((name="log4j.logger.mrw.fn.std",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="OFF", (cont="OFF",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.logger.mrw.fn.CppUnit", properties.setProperty((name="log4j.logger.mrw.fn.CppUnit",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="OFF", (cont="OFF",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.logger.mrw.fn.__gnu_cxx", properties.setProperty((name="log4j.logger.mrw.fn.__gnu_cxx",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="OFF", (cont="OFF",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.appender.A1", properties.setProperty((name="log4j.appender.A1",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="org.apache.log4j.ConsoleAppender", (cont="org.apache.log4j.ConsoleAppender",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.appender.A1.layout", properties.setProperty((name="log4j.appender.A1.layout",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="org.apache.log4j.PatternLayout", (cont="org.apache.log4j.PatternLayout",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
#ifdef _MT #ifdef _MT
properties.setProperty((name="log4j.appender.A1.layout.ConversionPattern", 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", (cont="%t-%-40l - %m%n",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
#else #else
properties.setProperty((name="log4j.appender.A1.layout.ConversionPattern", properties.setProperty((name="log4j.appender.A1.layout.ConversionPattern",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="%-40l - %m%n", (cont="%-40l - %m%n",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
#endif #endif
log4cxx::PropertyConfigurator::configure(properties); log4cxx::PropertyConfigurator::configure(properties);
} }

@ -253,10 +253,10 @@ namespace mrw {
_tracer(tracer.begin(), tracer.end()) { _tracer(tracer.begin(), tracer.end()) {
log4cxx::Logger* logger(log4cxx::Logger::getLogger(_tracer)); log4cxx::Logger* logger(log4cxx::Logger::getLogger(_tracer));
if (logger->isDebugEnabled()) { 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<<": " oss<<std::hex<<std::setw(15)<<_addr<<": "
<<std::dec<<std::setw(2+_level) <<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(), logger->forcedLog(MRW_LEVEL_DEBUG, oss.str(),
MRW_LOG4CXX_LOCATION); MRW_LOG4CXX_LOCATION);
++_level; ++_level;
@ -269,9 +269,9 @@ namespace mrw {
_tracer(tracer.begin(), tracer.end()) { _tracer(tracer.begin(), tracer.end()) {
log4cxx::Logger* logger(log4cxx::Logger::getLogger(_tracer)); log4cxx::Logger* logger(log4cxx::Logger::getLogger(_tracer));
if (logger->isDebugEnabled()) { if (logger->isDebugEnabled()) {
std::basic_stringstream<log4cxx::String::value_type> oss; std::basic_stringstream<std::string::value_type> oss;
oss<<std::setw(17)<<' ' 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; <<"\\ "<<_name;
logger->forcedLog(MRW_LEVEL_DEBUG, oss.str(), logger->forcedLog(MRW_LEVEL_DEBUG, oss.str(),
MRW_LOG4CXX_LOCATION); MRW_LOG4CXX_LOCATION);
@ -282,12 +282,12 @@ namespace mrw {
log4cxx::Logger* logger(log4cxx::Logger::getLogger(_tracer)); log4cxx::Logger* logger(log4cxx::Logger::getLogger(_tracer));
if (logger->isDebugEnabled()) { if (logger->isDebugEnabled()) {
--_level; --_level;
std::basic_stringstream<log4cxx::String::value_type> oss; std::basic_stringstream<std::string::value_type> oss;
if (_addr) if (_addr)
oss<<std::hex<<std::setw(15)<<_addr<<": "<<std::dec; oss<<std::hex<<std::setw(15)<<_addr<<": "<<std::dec;
else else
oss<<std::setw(17)<<' '; 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; <<"/ "<<_name;
logger->forcedLog(MRW_LEVEL_DEBUG, oss.str(), logger->forcedLog(MRW_LEVEL_DEBUG, oss.str(),
MRW_LOG4CXX_LOCATION); MRW_LOG4CXX_LOCATION);
@ -295,10 +295,10 @@ namespace mrw {
} }
private: private:
const void* _addr; const void* _addr;
const log4cxx::String _name; const std::string _name;
const std::string _file; const std::string _file;
unsigned long _line; unsigned long _line;
const log4cxx::String _tracer; const std::string _tracer;
/** @todo for multithreading, use thread specific storage */ /** @todo for multithreading, use thread specific storage */
static unsigned int _level; static unsigned int _level;
}; };

@ -74,25 +74,25 @@ class FunctionTraceTest: public CppUnit::TestFixture {
log4cxx::helpers::Properties properties; log4cxx::helpers::Properties properties;
std::string name, cont; std::string name, cont;
properties.setProperty((name="log4j.rootLogger", properties.setProperty((name="log4j.rootLogger",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="DEBUG, A1", (cont="DEBUG, A1",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.appender.A1", properties.setProperty((name="log4j.appender.A1",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="org.apache.log4j.FileAppender", (cont="org.apache.log4j.FileAppender",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.appender.A1.layout", properties.setProperty((name="log4j.appender.A1.layout",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="org.apache.log4j.PatternLayout", (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", 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", (cont="%F:%L - %m%n",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.appender.A1.filename", properties.setProperty((name="log4j.appender.A1.filename",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="functiontrace_test.log", (cont="functiontrace_test.log",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
log4cxx::PropertyConfigurator::configure(properties); log4cxx::PropertyConfigurator::configure(properties);
} }
void Calls() { void Calls() {

@ -156,7 +156,7 @@ if AUTOFNTRACE
mrwautofunctiontracelog4cxx_test_LDFLAGS = \ mrwautofunctiontracelog4cxx_test_LDFLAGS = \
@CPPUNIT_LIBS@ -L${top_builddir}/src -finstrument-functions @CPPUNIT_LIBS@ -L${top_builddir}/src -finstrument-functions
mrwautofunctiontracelog4cxx_test_LDADD = \ mrwautofunctiontracelog4cxx_test_LDADD = \
-llog4cxx -lmrwautofunctiontracelog4cxx -llog4cxx -lmrwautofunctiontracelog4cxx -lmrw
if HAVE_THREADS if HAVE_THREADS
if HAVE_BOOST_THREAD if HAVE_BOOST_THREAD
mrwautofunctiontracelog4cxx_test_mt_SOURCES = \ mrwautofunctiontracelog4cxx_test_mt_SOURCES = \
@ -168,7 +168,7 @@ if HAVE_BOOST_THREAD
mrwautofunctiontracelog4cxx_test_mt_LDFLAGS = \ mrwautofunctiontracelog4cxx_test_mt_LDFLAGS = \
@CPPUNIT_LIBS@ -L${top_builddir}/src @THREADS@ -finstrument-functions @CPPUNIT_LIBS@ -L${top_builddir}/src @THREADS@ -finstrument-functions
mrwautofunctiontracelog4cxx_test_mt_LDADD = \ mrwautofunctiontracelog4cxx_test_mt_LDADD = \
-llog4cxx -lmrwautofunctiontracelog4cxx-mt @BOOST_THREAD_LIB@ -llog4cxx -lmrwautofunctiontracelog4cxx-mt -lmrw @BOOST_THREAD_LIB@
endif endif
endif endif
endif endif

@ -67,7 +67,7 @@ void anotherFunction() {
} }
#ifdef _MT #ifdef _MT
#include <boost/thread/thread.hxx> #include <boost/thread/thread.hpp>
//#include <unistd.h> // sleep, the one from boost::thread does not work! //#include <unistd.h> // sleep, the one from boost::thread does not work!
class Thread { class Thread {
public: public:
@ -91,91 +91,91 @@ namespace mrw {
log4cxx::helpers::Properties properties; log4cxx::helpers::Properties properties;
std::string name, cont; std::string name, cont;
properties.setProperty((name="log4j.rootLogger", properties.setProperty((name="log4j.rootLogger",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="OFF, A1", (cont="OFF, A1",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.logger.mrw.fn", properties.setProperty((name="log4j.logger.mrw.fn",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="DEBUG", (cont="DEBUG",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.logger.mrw.fn.global", properties.setProperty((name="log4j.logger.mrw.fn.global",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="OFF", (cont="OFF",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.logger.mrw.fn.allocator", properties.setProperty((name="log4j.logger.mrw.fn.allocator",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="OFF", (cont="OFF",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.logger.mrw.fn.std.*", properties.setProperty((name="log4j.logger.mrw.fn.std.*",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="OFF", (cont="OFF",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.logger.mrw.fn.log4cxx", properties.setProperty((name="log4j.logger.mrw.fn.log4cxx",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="OFF", (cont="OFF",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.logger.mrw.fn.boost", properties.setProperty((name="log4j.logger.mrw.fn.boost",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="OFF", (cont="OFF",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.logger.mrw.fn.Thread", properties.setProperty((name="log4j.logger.mrw.fn.Thread",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="OFF", (cont="OFF",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.logger.mrw.fn.mrw", properties.setProperty((name="log4j.logger.mrw.fn.mrw",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="OFF", (cont="OFF",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.logger.mrw.fn.std", properties.setProperty((name="log4j.logger.mrw.fn.std",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="OFF", (cont="OFF",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.logger.mrw.fn.new", properties.setProperty((name="log4j.logger.mrw.fn.new",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="OFF", (cont="OFF",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.logger.mrw.fn.CppUnit", properties.setProperty((name="log4j.logger.mrw.fn.CppUnit",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="OFF", (cont="OFF",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.logger.mrw.fn.__gnu_cxx", properties.setProperty((name="log4j.logger.mrw.fn.__gnu_cxx",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="OFF", (cont="OFF",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.appender.A1", properties.setProperty((name="log4j.appender.A1",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="org.apache.log4j.FileAppender", (cont="org.apache.log4j.FileAppender",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.appender.A1.layout", properties.setProperty((name="log4j.appender.A1.layout",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="org.apache.log4j.PatternLayout", (cont="org.apache.log4j.PatternLayout",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
#ifdef _MT #ifdef _MT
properties.setProperty((name="log4j.appender.A1.layout.ConversionPattern", 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", (cont="%t-%-27c%m%n",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.appender.A1.filename", properties.setProperty((name="log4j.appender.A1.filename",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="mrwautofunctiontracelog4cxx_test-mt.log", (cont="mrwautofunctiontracelog4cxx_test-mt.log",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
#else #else
properties.setProperty((name="log4j.appender.A1.layout.ConversionPattern", properties.setProperty((name="log4j.appender.A1.layout.ConversionPattern",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="%-27c%m%n", (cont="%-27c%m%n",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
properties.setProperty((name="log4j.appender.A1.filename", properties.setProperty((name="log4j.appender.A1.filename",
log4cxx::String(name.begin(), name.end())), std::string(name.begin(), name.end())),
(cont="mrwautofunctiontracelog4cxx_test.log", (cont="mrwautofunctiontracelog4cxx_test.log",
log4cxx::String(cont.begin(), cont.end()))); std::string(cont.begin(), cont.end())));
#endif #endif
log4cxx::PropertyConfigurator::configure(properties); log4cxx::PropertyConfigurator::configure(properties);
#ifdef _MT #ifdef _MT
// sleep(4); // to be reproducable, wait for "main" flag // sleep(4); // to be reproducable, wait for "main" flag
Thread threadFunction; Thread threadFunction;
boost::thread::thread thread1(threadFunction); boost::thread thread1(threadFunction);
boost::thread::thread thread2(threadFunction); boost::thread thread2(threadFunction);
boost::thread::thread thread3(threadFunction); boost::thread thread3(threadFunction);
#endif #endif
anotherFunction(); anotherFunction();
#ifdef _MT #ifdef _MT

Loading…
Cancel
Save