Switch to unified view

a b/src/utils/debuglog.h
1
#ifndef _DEBUGLOG_H_
2
#define _DEBUGLOG_H_
3
/* Macros for log and debug messages */
4
#include <stack>
5
6
#ifndef NO_NAMESPACES
7
namespace DebugLog {
8
    using std::stack;
9
#endif // NO_NAMESPACES
10
11
#ifndef DEBUGLOG_USE_THREADS
12
#define DEBUGLOG_USE_THREADS 1
13
#endif
14
15
#define DEBFATAL 1
16
#define DEBERR   2
17
#define DEBINFO  3
18
#define DEBDEB   4
19
#define DEBDEB0  5
20
#define DEBDEB1  6
21
#define DEBDEB2  7
22
#define DEBDEB3  8
23
24
#ifndef STATICVERBOSITY
25
#define STATICVERBOSITY DEBDEB0
26
#endif
27
28
class DebugLogWriter;
29
30
class DebugLog {
31
    std::stack<int> levels;
32
    int debuglevel;
33
    int dodate;
34
    DebugLogWriter *writer;
35
  public:
36
    DebugLog() : debuglevel(-1), dodate(0), writer(0) {}
37
    DebugLog(DebugLogWriter *w) : debuglevel(-1), dodate(0), writer(w) {}
38
    virtual ~DebugLog() {}
39
    virtual void setwriter(DebugLogWriter *w) {writer = w;}
40
    virtual DebugLogWriter *getwriter() {return writer;}
41
    virtual void prolog(int lev, const char *srcfname, int line);
42
    virtual void log(const char *s ...);
43
    virtual void setloglevel(int lev);
44
    inline int getlevel() {return debuglevel;}
45
    virtual void pushlevel(int lev);
46
    virtual void poplevel();
47
    virtual void logdate(int onoff) {dodate = onoff;}
48
};
49
50
extern DebugLog *getdbl();
51
extern const char *getfilename();
52
extern int setfilename(const char *fname, int trnc = 1);
53
#if STATICVERBOSITY >= DEBFATAL
54
#define LOGFATAL(X) {if (DebugLog::getdbl()->getlevel()>=DEBFATAL){DebugLog::getdbl()->prolog(DEBFATAL,__FILE__,__LINE__) ;DebugLog::getdbl()->log X;}}
55
#else
56
#define LOGFATAL(X)
57
#endif
58
#if STATICVERBOSITY >= DEBERR
59
#define LOGERR(X) {if (DebugLog::getdbl()->getlevel()>=DEBERR){DebugLog::getdbl()->prolog(DEBERR,__FILE__,__LINE__) ;DebugLog::getdbl()->log X;}}
60
#else
61
#define LOGERR(X)
62
#endif
63
#if STATICVERBOSITY >= DEBINFO
64
#define LOGINFO(X) {if (DebugLog::getdbl()->getlevel()>=DEBINFO){DebugLog::getdbl()->prolog(DEBINFO,__FILE__,__LINE__) ;DebugLog::getdbl()->log X;}}
65
#else
66
#define LOGINFO(X)
67
#endif
68
#if STATICVERBOSITY >= DEBDEB
69
#define LOGDEB(X) {if (DebugLog::getdbl()->getlevel()>=DEBDEB){DebugLog::getdbl()->prolog(DEBDEB,__FILE__,__LINE__) ;DebugLog::getdbl()->log X;}}
70
#else
71
#define LOGDEB(X)
72
#endif
73
#if STATICVERBOSITY >= DEBDEB0
74
#define LOGDEB0(X) {if (DebugLog::getdbl()->getlevel()>=DEBDEB0){DebugLog::getdbl()->prolog(DEBDEB0,__FILE__,__LINE__) ;DebugLog::getdbl()->log X;}}
75
#else
76
#define LOGDEB0(X)
77
#endif
78
#if STATICVERBOSITY >= DEBDEB1
79
#define LOGDEB1(X) {if (DebugLog::getdbl()->getlevel()>=DEBDEB1){DebugLog::getdbl()->prolog(DEBDEB1,__FILE__,__LINE__) ;DebugLog::getdbl()->log X;}}
80
#else
81
#define LOGDEB1(X)
82
#endif
83
#if STATICVERBOSITY >= DEBDEB2
84
#define LOGDEB2(X) {if (DebugLog::getdbl()->getlevel()>=DEBDEB2){DebugLog::getdbl()->prolog(DEBDEB2,__FILE__,__LINE__) ;DebugLog::getdbl()->log X;}}
85
#else
86
#define LOGDEB2(X)
87
#endif
88
#if STATICVERBOSITY >= DEBDEB3
89
#define LOGDEB3(X) {if (DebugLog::getdbl()->getlevel()>=DEBDEB3){DebugLog::getdbl()->prolog(DEBDEB3,__FILE__,__LINE__) ;DebugLog::getdbl()->log X;}}
90
#else
91
#define LOGDEB3(X)
92
#endif
93
#if STATICVERBOSITY >= DEBDEB4
94
#define LOGDEB4(X) {if (DebugLog::getdbl()->getlevel()>=DEBDEB4){DebugLog::getdbl()->prolog(DEBDEB4,__FILE__,__LINE__) ;DebugLog::getdbl()->log X;}}
95
#else
96
#define LOGDEB4(X)
97
#endif
98
#ifndef NO_NAMESPACES
99
}
100
#endif // NO_NAMESPACES
101
#endif /* _DEBUGLOG_H_ */