Electroneum
Toggle main menu visibility
Loading...
Searching...
No Matches
misc_log_ex.h
Go to the documentation of this file.
1
// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
2
// All rights reserved.
3
//
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions are met:
6
// * Redistributions of source code must retain the above copyright
7
// notice, this list of conditions and the following disclaimer.
8
// * Redistributions in binary form must reproduce the above copyright
9
// notice, this list of conditions and the following disclaimer in the
10
// documentation and/or other materials provided with the distribution.
11
// * Neither the name of the Andrey N. Sabelnikov nor the
12
// names of its contributors may be used to endorse or promote products
13
// derived from this software without specific prior written permission.
14
//
15
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY
19
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
//
26
27
28
#ifndef _MISC_LOG_EX_H_
29
#define _MISC_LOG_EX_H_
30
31
#include <string>
32
33
#include "
easylogging++.h
"
34
35
#undef ELECTRONEUM_DEFAULT_LOG_CATEGORY
36
#define ELECTRONEUM_DEFAULT_LOG_CATEGORY "default"
37
38
#define MAX_LOG_FILE_SIZE 104850000
// 100 MB - 7600 bytes
39
#define MAX_LOG_FILES 50
40
41
#define MCLOG_TYPE(level, cat, type, x) do { \
42
if (ELPP->vRegistry()->allowed(level, cat)) { \
43
el::base::Writer(level, __FILE__, __LINE__, ELPP_FUNC, type).construct(cat) << x; \
44
} \
45
} while (0)
46
47
#define MCLOG(level, cat, x) MCLOG_TYPE(level, cat, el::base::DispatchAction::NormalLog, x)
48
#define MCLOG_FILE(level, cat, x) MCLOG_TYPE(level, cat, el::base::DispatchAction::FileOnlyLog, x)
49
50
#define MCFATAL(cat,x) MCLOG(el::Level::Fatal,cat, x)
51
#define MCERROR(cat,x) MCLOG(el::Level::Error,cat, x)
52
#define MCWARNING(cat,x) MCLOG(el::Level::Warning,cat, x)
53
#define MCINFO(cat,x) MCLOG(el::Level::Info,cat, x)
54
#define MCDEBUG(cat,x) MCLOG(el::Level::Debug,cat, x)
55
#define MCTRACE(cat,x) MCLOG(el::Level::Trace,cat, x)
56
57
#define MCLOG_COLOR(level,cat,color,x) MCLOG(level,cat,"\033[1;" color "m" << x << "\033[0m")
58
#define MCLOG_RED(level,cat,x) MCLOG_COLOR(level,cat,"31",x)
59
#define MCLOG_GREEN(level,cat,x) MCLOG_COLOR(level,cat,"32",x)
60
#define MCLOG_YELLOW(level,cat,x) MCLOG_COLOR(level,cat,"33",x)
61
#define MCLOG_BLUE(level,cat,x) MCLOG_COLOR(level,cat,"34",x)
62
#define MCLOG_MAGENTA(level,cat,x) MCLOG_COLOR(level,cat,"35",x)
63
#define MCLOG_CYAN(level,cat,x) MCLOG_COLOR(level,cat,"36",x)
64
65
#define MLOG_RED(level,x) MCLOG_RED(level,ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)
66
#define MLOG_GREEN(level,x) MCLOG_GREEN(level,ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)
67
#define MLOG_YELLOW(level,x) MCLOG_YELLOW(level,ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)
68
#define MLOG_BLUE(level,x) MCLOG_BLUE(level,ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)
69
#define MLOG_MAGENTA(level,x) MCLOG_MAGENTA(level,ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)
70
#define MLOG_CYAN(level,x) MCLOG_CYAN(level,ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)
71
72
#define MFATAL(x) MCFATAL(ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)
73
#define MERROR(x) MCERROR(ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)
74
#define MWARNING(x) MCWARNING(ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)
75
#define MINFO(x) MCINFO(ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)
76
#define MDEBUG(x) MCDEBUG(ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)
77
#define MTRACE(x) MCTRACE(ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)
78
#define MLOG(level,x) MCLOG(level,ELECTRONEUM_DEFAULT_LOG_CATEGORY,x)
79
80
#define MGINFO(x) MCINFO("global",x)
81
#define MGINFO_RED(x) MCLOG_RED(el::Level::Info, "global",x)
82
#define MGINFO_GREEN(x) MCLOG_GREEN(el::Level::Info, "global",x)
83
#define MGINFO_YELLOW(x) MCLOG_YELLOW(el::Level::Info, "global",x)
84
#define MGINFO_BLUE(x) MCLOG_BLUE(el::Level::Info, "global",x)
85
#define MGINFO_MAGENTA(x) MCLOG_MAGENTA(el::Level::Info, "global",x)
86
#define MGINFO_CYAN(x) MCLOG_CYAN(el::Level::Info, "global",x)
87
88
#define IFLOG(level, cat, type, init, x) \
89
do { \
90
if (ELPP->vRegistry()->allowed(level, cat)) { \
91
init; \
92
el::base::Writer(level, __FILE__, __LINE__, ELPP_FUNC, type).construct(cat) << x; \
93
} \
94
} while(0)
95
#define MIDEBUG(init, x) IFLOG(el::Level::Debug, ELECTRONEUM_DEFAULT_LOG_CATEGORY, el::base::DispatchAction::NormalLog, init, x)
96
97
98
#define LOG_ERROR(x) MERROR(x)
99
#define LOG_PRINT_L0(x) MWARNING(x)
100
#define LOG_PRINT_L1(x) MINFO(x)
101
#define LOG_PRINT_L2(x) MDEBUG(x)
102
#define LOG_PRINT_L3(x) MTRACE(x)
103
#define LOG_PRINT_L4(x) MTRACE(x)
104
105
#define _dbg3(x) MTRACE(x)
106
#define _dbg2(x) MDEBUG(x)
107
#define _dbg1(x) MDEBUG(x)
108
#define _info(x) MINFO(x)
109
#define _note(x) MDEBUG(x)
110
#define _fact(x) MDEBUG(x)
111
#define _mark(x) MDEBUG(x)
112
#define _warn(x) MWARNING(x)
113
#define _erro(x) MERROR(x)
114
115
#define MLOG_SET_THREAD_NAME(x) el::Helpers::setThreadName(x)
116
117
#ifndef LOCAL_ASSERT
118
#include <assert.h>
119
#if (defined _MSC_VER)
120
#define LOCAL_ASSERT(expr) {if(epee::debug::get_set_enable_assert()){_ASSERTE(expr);}}
121
#else
122
#define LOCAL_ASSERT(expr)
123
#endif
124
125
#endif
126
127
std::string
mlog_get_default_log_path
(
const
char
*default_filename);
128
void
mlog_configure
(
const
std::string &filename_base,
bool
console,
const
std::size_t max_log_file_size =
MAX_LOG_FILE_SIZE
,
const
std::size_t max_log_files =
MAX_LOG_FILES
);
129
void
mlog_set_categories
(
const
char
*categories);
130
std::string
mlog_get_categories
();
131
void
mlog_set_log_level
(
int
level);
132
void
mlog_set_log
(
const
char
*log);
133
134
namespace
epee
135
{
136
namespace
debug
137
{
138
inline
bool
get_set_enable_assert
(
bool
set =
false
,
bool
v =
false
)
139
{
140
static
bool
e =
true
;
141
if
(set)
142
e = v;
143
return
e;
144
}
145
}
146
147
148
149
#define ENDL std::endl
150
151
#define TRY_ENTRY() try {
152
#define CATCH_ENTRY(location, return_val) } \
153
catch(const std::exception& ex) \
154
{ \
155
(void)(ex); \
156
LOG_ERROR("Exception at [" << location << "], what=" << ex.what()); \
157
return return_val; \
158
}\
159
catch(...)\
160
{\
161
LOG_ERROR("Exception at [" << location << "], generic exception \"...\"");\
162
return return_val; \
163
}
164
165
#define CATCH_ENTRY_L0(lacation, return_val) CATCH_ENTRY(lacation, return_val)
166
#define CATCH_ENTRY_L1(lacation, return_val) CATCH_ENTRY(lacation, return_val)
167
#define CATCH_ENTRY_L2(lacation, return_val) CATCH_ENTRY(lacation, return_val)
168
#define CATCH_ENTRY_L3(lacation, return_val) CATCH_ENTRY(lacation, return_val)
169
#define CATCH_ENTRY_L4(lacation, return_val) CATCH_ENTRY(lacation, return_val)
170
171
172
#define ASSERT_MES_AND_THROW(message) {LOG_ERROR(message); std::stringstream ss; ss << message; throw std::runtime_error(ss.str());}
173
#define CHECK_AND_ASSERT_THROW_MES(expr, message) do {if(!(expr)) ASSERT_MES_AND_THROW(message);} while(0)
174
175
176
#ifndef CHECK_AND_ASSERT
177
#define CHECK_AND_ASSERT(expr, fail_ret_val) do{if(!(expr)){LOCAL_ASSERT(expr); return fail_ret_val;};}while(0)
178
#endif
179
180
#ifndef CHECK_AND_ASSERT_MES
181
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message) do{if(!(expr)) {LOG_ERROR(message); return fail_ret_val;};}while(0)
182
#endif
183
184
#ifndef CHECK_AND_NO_ASSERT_MES_L
185
#define CHECK_AND_NO_ASSERT_MES_L(expr, fail_ret_val, l, message) do{if(!(expr)) {LOG_PRINT_L##l(message);
/*LOCAL_ASSERT(expr);*/
return fail_ret_val;};}while(0)
186
#endif
187
188
#ifndef CHECK_AND_NO_ASSERT_MES
189
#define CHECK_AND_NO_ASSERT_MES(expr, fail_ret_val, message) CHECK_AND_NO_ASSERT_MES_L(expr, fail_ret_val, 0, message)
190
#endif
191
192
#ifndef CHECK_AND_NO_ASSERT_MES_L1
193
#define CHECK_AND_NO_ASSERT_MES_L1(expr, fail_ret_val, message) CHECK_AND_NO_ASSERT_MES_L(expr, fail_ret_val, 1, message)
194
#endif
195
196
197
#ifndef CHECK_AND_ASSERT_MES_NO_RET
198
#define CHECK_AND_ASSERT_MES_NO_RET(expr, message) do{if(!(expr)) {LOG_ERROR(message); return;};}while(0)
199
#endif
200
201
202
#ifndef CHECK_AND_ASSERT_MES2
203
#define CHECK_AND_ASSERT_MES2(expr, message) do{if(!(expr)) {LOG_ERROR(message); };}while(0)
204
#endif
205
206
enum
console_colors
207
{
208
console_color_default
,
209
console_color_white
,
210
console_color_red
,
211
console_color_green
,
212
console_color_blue
,
213
console_color_cyan
,
214
console_color_magenta
,
215
console_color_yellow
216
};
217
218
bool
is_stdout_a_tty
();
219
void
set_console_color
(
int
color,
bool
bright);
220
void
reset_console_color
();
221
222
}
223
#endif
//_MISC_LOG_EX_H_
easylogging++.h
mlog_configure
void mlog_configure(const std::string &filename_base, bool console, const std::size_t max_log_file_size=MAX_LOG_FILE_SIZE, const std::size_t max_log_files=MAX_LOG_FILES)
Definition
mlog.cpp:148
mlog_get_default_log_path
std::string mlog_get_default_log_path(const char *default_filename)
Definition
mlog.cpp:72
mlog_get_categories
std::string mlog_get_categories()
Definition
mlog.cpp:276
mlog_set_log
void mlog_set_log(const char *log)
Definition
mlog.cpp:288
mlog_set_log_level
void mlog_set_log_level(int level)
Definition
mlog.cpp:282
MAX_LOG_FILES
#define MAX_LOG_FILES
Definition
misc_log_ex.h:39
mlog_set_categories
void mlog_set_categories(const char *categories)
Definition
mlog.cpp:238
MAX_LOG_FILE_SIZE
#define MAX_LOG_FILE_SIZE
Definition
misc_log_ex.h:38
epee::debug
Definition
misc_log_ex.h:137
epee::debug::get_set_enable_assert
bool get_set_enable_assert(bool set=false, bool v=false)
Definition
misc_log_ex.h:138
epee
Definition
ado_db_helper.h:67
epee::set_console_color
void set_console_color(int color, bool bright)
Definition
mlog.cpp:341
epee::reset_console_color
void reset_console_color()
Definition
mlog.cpp:460
epee::is_stdout_a_tty
bool is_stdout_a_tty()
Definition
mlog.cpp:323
epee::console_colors
console_colors
Definition
misc_log_ex.h:207
epee::console_color_red
@ console_color_red
Definition
misc_log_ex.h:210
epee::console_color_magenta
@ console_color_magenta
Definition
misc_log_ex.h:214
epee::console_color_yellow
@ console_color_yellow
Definition
misc_log_ex.h:215
epee::console_color_default
@ console_color_default
Definition
misc_log_ex.h:208
epee::console_color_green
@ console_color_green
Definition
misc_log_ex.h:211
epee::console_color_blue
@ console_color_blue
Definition
misc_log_ex.h:212
epee::console_color_white
@ console_color_white
Definition
misc_log_ex.h:209
epee::console_color_cyan
@ console_color_cyan
Definition
misc_log_ex.h:213
contrib
epee
include
misc_log_ex.h
Generated on
for Electroneum by
1.17.0