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

This commit is contained in:
Marc Wäckerlin
2012-07-06 09:35:05 +00:00
parent c5c8f82d05
commit c24a43ccb2
7 changed files with 121 additions and 119 deletions

View File

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

View File

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

View File

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