much more debug, back to initial handling; refs #169

This commit is contained in:
Marc Wäckerlin
2013-04-18 14:19:15 +00:00
parent 86bdcc8c75
commit 25d01618f6
7 changed files with 62 additions and 48 deletions

View File

@@ -14,23 +14,29 @@ namespace qbrowserlib {
unsigned int Log::_level(0);
Log::Log(const void* addr, const std::string& name,
const std::string& file, unsigned long line):
_debug(DEBUG), _addr(addr), _name(name), _file(file), _line(line) {
if (!_debug) return;
const std::string& file, unsigned long line,
bool traceOpenClose):
_debug(DEBUG), _close(traceOpenClose),
_addr(addr), _name(name), _file(file), _line(line) {
if (!_debug || !_close) return;
++_level;
std::stringstream ss;
init(ss);
// init(ss);
indent(ss)<<"\\ "<<_name;
std::clog<<close(ss).str()<<std::endl;
// std::clog<<close(ss).str()<<std::endl;
if (!_dialog) _dialog = new LogDialog;
_dialog->append(*this, ss.str());
}
Log::~Log() throw() {
if (!_debug) return;
if (!_debug || !_close) return;
std::stringstream ss;
init(ss);
// init(ss);
indent(ss)<<"/ "<<_name;
std::clog<<close(ss).str()<<std::endl;
// std::clog<<close(ss).str()<<std::endl;
--_level;
if (!_dialog) _dialog = new LogDialog;
_dialog->append(*this, ss.str());
}
void Log::show(QWidget* p) {

View File

@@ -13,6 +13,7 @@
#include <QtGui/QDialog>
#endif
#include <stdexcept>
#include <sstream>
#include <iostream>
#include <iomanip>
@@ -29,8 +30,6 @@ namespace qbrowserlib {
#ifndef LOG
#define LOG \
QBROWSERLIB_LOCAL_TRACER
// #define LOG
// qbrowserlib::Log(1, __PRETTY_FUNCTION__, __FILE__, __LINE__)
#endif
#ifndef TRC
@@ -45,6 +44,29 @@ namespace qbrowserlib {
(0, __PRETTY_FUNCTION__, __FILE__, __LINE__)
#endif
#define CRYPTOKI_LOG(X) \
qbrowserlib::Log(0, __PRETTY_FUNCTION__, __FILE__, __LINE__, false)<<X
#define PCSC_LOG(X) \
qbrowserlib::Log(0, __PRETTY_FUNCTION__, __FILE__, __LINE__, false)<<X
#define OPENSSL_LOG(X) \
qbrowserlib::Log(0, __PRETTY_FUNCTION__, __FILE__, __LINE__, false)<<X
#define OPENSSL_CHECK(X) \
if (!X) { \
ERR_load_ENGINE_strings(); \
std::stringstream ss; \
for (unsigned int err(0); err=ERR_get_error();) { \
ss<<"Error: "<<ERR_error_string(err, 0)<<"; "; \
} \
ss<<"Command "<<#X<<" failed in function "<<__PRETTY_FUNCTION__ \
<<" in file "<<__FILE__<<":"<<__LINE__; \
qbrowserlib::Log(0, __PRETTY_FUNCTION__, __FILE__, __LINE__, false) \
<<ss.str(); \
throw std::runtime_error(ss.str()); \
}
class LogDialog;
class Log {
@@ -56,7 +78,8 @@ namespace qbrowserlib {
public:
Log(const void* addr, const std::string& name,
const std::string& file, unsigned long line);
const std::string& file, unsigned long line,
bool traceOpenClose=true);
template<typename TYPE> Log& operator<<(TYPE arg);
@@ -79,6 +102,7 @@ namespace qbrowserlib {
static LogDialog* _dialog;
static unsigned int _level;
bool _debug;
bool _close;
const void* _addr;
const std::string _name;
const std::string _file;
@@ -193,11 +217,11 @@ namespace qbrowserlib {
template<typename TYPE> Log& Log::operator<<(TYPE arg) {
if (!_debug) return *this;
std::stringstream ss;
init(ss);
// init(ss);
indent(ss)<<""<<arg;
std::clog<<close(ss).str()<<std::endl;
// std::clog<<close(ss).str()<<std::endl;
if (!_dialog) _dialog = new LogDialog;
_dialog->append(*this, arg);
_dialog->append(*this, ss.str());
return *this;
}