114 lines
2.4 KiB
C++
114 lines
2.4 KiB
C++
#ifndef _TRISKELE_DEBUG_HPP
|
|
#define _TRISKELE_DEBUG_HPP
|
|
|
|
#include <iostream>
|
|
#include <iomanip>
|
|
#include <string>
|
|
#include <sstream>
|
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
|
#include <boost/chrono.hpp>
|
|
|
|
|
|
#ifdef ENABLE_SMART_LOG
|
|
|
|
#ifndef SMART_DEF_LOG
|
|
#define SMART_DEF_LOG(name, expr) DEF_LOG (name, expr)
|
|
#endif
|
|
|
|
#ifndef SMART_LOG
|
|
#define SMART_LOG(expr) LOG (expr)
|
|
#endif
|
|
|
|
#ifndef SMART_LOG_EXPR
|
|
#define SMART_LOG_EXPR(expr) {if (::triskele::debug) {expr;} }
|
|
#endif
|
|
|
|
#else
|
|
|
|
#ifndef SMART_DEF_LOG
|
|
#define SMART_DEF_LOG(name, expr)
|
|
#endif
|
|
|
|
#ifndef SMART_LOG
|
|
#define SMART_LOG(expr)
|
|
#endif
|
|
|
|
#ifndef SMART_LOG_EXPR
|
|
#define SMART_LOG_EXPR(expr)
|
|
#endif
|
|
#endif
|
|
|
|
#ifdef DISABLE_LOG
|
|
|
|
#ifndef DEF_LOG
|
|
#define DEF_LOG(name, expr)
|
|
#endif
|
|
#ifndef LOG
|
|
#define LOG(expr) {}
|
|
#endif
|
|
|
|
#ifndef DEBUG
|
|
#define DEBUG(expr) {}
|
|
#endif
|
|
|
|
#else
|
|
|
|
#ifndef DEF_LOG
|
|
#define DEF_LOG(name, expr) ::triskele::Log log (name); { if (::triskele::debug) cerr << expr << endl << flush; }
|
|
#endif
|
|
|
|
#ifndef LOG
|
|
#define LOG(expr) { if (::triskele::debug) cerr << log << "| " << expr << endl << flush; }
|
|
#endif
|
|
|
|
#ifndef DEBUG
|
|
#define DEBUG(expr) { if (::triskele::debug) cerr << expr << endl << flush; }
|
|
#endif
|
|
|
|
#endif
|
|
|
|
namespace triskele {
|
|
|
|
extern bool debug;
|
|
|
|
using namespace std;
|
|
|
|
// =======================================
|
|
|
|
inline std::string getLocalTimeStr () {
|
|
using namespace boost::posix_time;
|
|
using namespace std;
|
|
ptime now = second_clock::second_clock::local_time ();
|
|
stringstream ss;
|
|
auto date = now.date ();
|
|
auto time = now.time_of_day ();
|
|
ss << setfill ('0') << "["
|
|
<< setw (2) << static_cast<int> (date.month ()) << "/" << setw (2) << date.day ()
|
|
<< "] " << setw (2)
|
|
<< time.hours () << ":" << setw (2) << time.minutes ();
|
|
return ss.str();
|
|
}
|
|
|
|
// ========================================
|
|
using namespace std;
|
|
|
|
class Log {
|
|
static unsigned int indent;
|
|
string functName;
|
|
public:
|
|
Log (const string &functName) : functName (functName) { ++indent; if (::triskele::debug) cerr << *this << "> "; }
|
|
~Log () { if (::triskele::debug) cerr << *this << "<" << endl << flush; --indent; }
|
|
friend inline ostream &operator << (ostream &out, const Log &log) {
|
|
return out << getLocalTimeStr () << setw (3) << setw ((log.indent % 20)*2) << "" << log.functName;
|
|
}
|
|
};
|
|
|
|
inline string ns2string (double delta);
|
|
|
|
// ========================================
|
|
#include "triskeleDebug.tpp"
|
|
|
|
}//namespace triskele
|
|
|
|
#endif //_TRISKELE_DEBUG_HPP
|