-
Notifications
You must be signed in to change notification settings - Fork 1
/
jlog.hpp
138 lines (119 loc) · 3.13 KB
/
jlog.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#ifndef __JLOG_H
#define __JLOG_H
#include <istream>
#include <iomanip>
//! \file jlog.hpp
//! \brief Simple Error/Log/Trace/Debug macros.
//!
//! Follows syntax of std::cout, but the arguments have to be
//! enclosed in parentheses. Newlines and endl operators are not
//! required. Messages are prefixed with Message type, file name, line
//! and two characters indicating the type of message.
//!
//! Type | Message | Value |Indicators
//! ------|---------|-------|----------
//! Error | ERROR | 2 | ==
//! Warn | WARN | 4 | =-
//! Log | LOG | 8 | --
//! Info | INFO | 16 | -+
//! Debug | DEBUG | 32 | +-
//! Trace | TRACE | 64 | ++
//!
//! Available log levels.
typedef enum {FATAL = 1, ERROR = 2, WARN = 4, LOG = 8, INFO = 16, DBG = 32, TRACE = 64} LVLS;
extern int JLFWIDT;
extern int JLLWIDT;
extern int JLOGLVL;
extern int JMINLVL;
//! Width for file name in debug statements.
#define FILE_W 13
//! Width for line number in debug statements.
#define LINE_W 4
//! Set the log level.
//! MIN Level ensures that critical messages are not turned off by mistake.
#define SETMSGLVL(lvl) \
{ \
JLOGLVL = JMINLVL | lvl; \
}
// jLOG ("Setting log level to " << #lvl << " : " << lvl);
//! Turn on a particular log level.
#define TURNON(lvl) \
{ \
SETMSGLVL (JLOGLVL | lvl); \
}
//! Turn off a particular log level.
#define TURNOFF(lvl) \
{ \
SETMSGLVL ( ((~lvl) & JLOGLVL)); \
}
//! Set the width for file names in log messages.
#define SETFWDT(width) do {JLFWIDT = width;} while (0)
//! Set the width for line numbers in log messages.
#define SETLWDT(width) do {JLLWIDT = width;} while (0)
//! Displays Error message
#define jERR(x) \
do \
{ \
std::cout << "[ERROR :" << setw (JLFWIDT) << __FILE__ << ":" \
<< std::setw (JLLWIDT) << __LINE__ << "] " \
<< "== [" << x << "]" << std::endl; \
} \
while (0)
//! Displays warning message
#define jWARN(x) \
do \
{ \
std::cout << "[WARN :" << setw (JLFWIDT) << __FILE__ << ":" \
<< std::setw (JLLWIDT) << __LINE__ << "] " \
<< "=- [" << x << "]" << std::endl; \
} \
while (0)
//! Displays Log message
#define jLOG(x) \
do \
{ \
if (JLOGLVL >= LOG) \
{ \
std::cout << "[LOG :" << setw (JLFWIDT) << __FILE__ << ":" \
<< std::setw (JLLWIDT) << __LINE__ << "] " \
<< "-- [" << x << "]" << std::endl; \
} \
} \
while (0)
//! Displays Info message
#define jINFO(x) \
do \
{ \
if (JLOGLVL >= INFO) \
{ \
std::cout << "[INFO :" << setw (JLFWIDT) << __FILE__ << ":" \
<< std::setw (JLLWIDT) << __LINE__ << "] " \
<< "-+ [" << x << "]" << std::endl; \
} \
} \
while (0)
//! Displays Debug message
#define jDBG(x) \
do \
{ \
if (JLOGLVL >= DBG) \
{ \
std::cout << "[DEBUG :" << setw (JLFWIDT) << __FILE__ << ":" \
<< std::setw (JLLWIDT) << __LINE__ << "] " \
<< "+- [" << x << "]" << std::endl; \
} \
} \
while (0)
//! Displays Trace message
#define jTRACE(x) \
do \
{ \
if (JLOGLVL >= TRACE) \
{ \
std::cout << "[TRACE :" << setw (JLFWIDT) << __FILE__ << ":" \
<< std::setw (JLLWIDT) << __LINE__ << "] " \
<< "++ [" << x << "]" << std::endl; \
} \
} \
while (0)
#endif