-
Notifications
You must be signed in to change notification settings - Fork 112
/
GETrace.h
351 lines (305 loc) · 15.7 KB
/
GETrace.h
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
#ifndef AREG_TRACE_GETRACE_H
#define AREG_TRACE_GETRACE_H
/************************************************************************
* This file is part of the AREG SDK core engine.
* AREG SDK is dual-licensed under Free open source (Apache version 2.0
* License) and Commercial (with various pricing models) licenses, depending
* on the nature of the project (commercial, research, academic or free).
* You should have received a copy of the AREG SDK license description in LICENSE.txt.
* If not, please contact to info[at]aregtech.com
*
* \copyright (c) 2017-2023 Aregtech UG. All rights reserved.
* \file areg/trace/GETrace.h
* \ingroup AREG SDK, Automated Real-time Event Grid Software Development Kit
* \author Artak Avetyan
* \brief NETrace namespace contains , structures and types.
*
************************************************************************/
/************************************************************************
* Include files.
************************************************************************/
#include "areg/base/GEGlobal.h"
#include "areg/trace/NETrace.hpp"
#include "areg/trace/TraceScope.hpp"
#include "areg/trace/TraceMessage.hpp"
/**
* \brief Use these MACRO instead of direct declaration of scopes
* and messaging. The MACRO gives possibility to compile application(s)
* either with logging, or only with output on Debug output window,
* or ignore any logging activity.
*
* AREG_LOGS is a global preprocessor definition
* indicating whether the applications should be compiled with
* logging or not. If this is not defined or zero,
* logging functionalities will be ignored, unless developer
* is not explicitly setting scopes and manually activating tracing.
*
* \example Start Logging:
* In this example, the application configures logging from default configuration file
* and start logging, to that the messages can be logged on target.
* ...
* TRACER_START_LOGGING(nullptr);
*
* \example Logging:
* In this example, the application created scope, which are used to start output messages.
* Depending on scope enabled priority, the appropriate message is logged.
* If scope priority is DEBUG, all message are logged.
* If scope enabled to output enter and exit, before any message is logged,
* the scope 'enter' message is logged on output target and when function is
* executed, at the end scope 'exit' message is logged.
* The scope should be declared before it is used. It can be used just before
* method where it is used. The scope should be declared only once, but can be
* used in more than one method.
* ...
* DEF_TRACE_SCOPE(my_message_scope_in_MyFunction);
* void MyFunction( void )
* {
* TRACE_SCOPE(my_message_scope_in_MyFunction);
*
* TRACE_DBG("If debug priority is enabled, this message is logged");
* TRACE_INFO("If logging priority is info of debug, this message is logged");
* TRACE_WARN("If logging priority is warn, info or debug, this message is logged");
* TRACE_ERROR("If logging priority is error, warn, info or debug, this message is logged");
* TRACE_FATAL("If logging priority is set, this message is logged");
* }
**/
#if AREG_LOGS
//////////////////////////////////////////////////////////////////////////
// if AREG_LOGS is defined, set logging priorities
//////////////////////////////////////////////////////////////////////////
//!< Priority to log everything
#define PRIO_LOG_ALL (static_cast<unsigned int>(NETrace::eLogPriority::PrioDebug) | static_cast<unsigned int>(NETrace::eLogPriority::PrioScope))
//!< Priority to log info, warnings, error and fatal
#define PRIO_INFO (static_cast<unsigned int>(NETrace::eLogPriority::PrioInfo) | static_cast<unsigned int>(NETrace::eLogPriority::PrioScope))
//!< Priority to log warnings, error and fatal
#define PRIO_WARNING (static_cast<unsigned int>(NETrace::eLogPriority::PrioWarning) | static_cast<unsigned int>(NETrace::eLogPriority::PrioScope))
//!< Priority to log error and fatal
#define PRIO_ERROR (static_cast<unsigned int>(NETrace::eLogPriority::PrioError) | static_cast<unsigned int>(NETrace::eLogPriority::PrioScope))
//!< Priority to log only fatal
#define PRIO_FATAL (static_cast<unsigned int>(NETrace::eLogPriority::PrioFatal) | static_cast<unsigned int>(NETrace::eLogPriority::PrioScope))
//!< Unset logging scopes in priorities
#define PRIO_NOSCOPES(x) ((x) & (~static_cast<unsigned int>(NETrace::eLogPriority::PrioScope)))
//!< No logging
#define PRIO_NOLOGS (static_cast<unsigned int>(NETrace::eLogPriority::PrioNotset))
/**
* \brief Change scope log priority during runtime.
* Pass scope set in DEF_TRACE_SCOPE and priority value with OR operation specified in NETrace::eLogPriority.
**/
#define SCOPE_PRIORITY_CHANGE(scope, prio) NETrace::setScopePriority(#scope, static_cast<unsigned int>(prio))
/**
* \brief Get the actual priority of the scope. Pass scope set in DEF_TRACE_SCOPE.
**/
#define SCOPE_PRIORITY_GET(scope) NETrace::getScopePriority(#scope)
//////////////////////////////////////////////////////////////////////////
// if AREG_LOGS is defined and not zero
//////////////////////////////////////////////////////////////////////////
/**
* \brief Returns true if logging is already configured and started
**/
#define IS_TRACE_STARTED() NETrace::isStarted()
/**
* \brief Returns true if logging is enabled
**/
#define IS_LOG_ENABLED() NETrace::isEnabled()
/**
* \brief Use this macro to load configuration file and start tracer.
* If config file name is nullptr, it will load from default folder "./config/areg.init"
**/
#define TRACER_START_LOGGING(configFile) NETrace::startLogging((configFile))
/**
* \brief Call to force to start logging.
**/
#define TRACER_FORCE_LOGGING() NETrace::forceStartLogging()
/**
* \brief Either configures logging values from file or sets default values, enables and starts logging
**/
#define TRACER_CONFIGURE_AND_START(configFile) NETrace::initAndStartLogging((configFile))
/**
* \brief Use this macro to stop logging. This blocks the calling thread until logging thread completes the job.
**/
#define TRACER_STOP_LOGGING() NETrace::stopLogging( true )
/**
* \brief Use this macro to define scope in source code. This will create scope variable and set name
**/
#define DEF_TRACE_SCOPE(scope) static TraceScope _##scope( #scope )
/**
* \brief Use this macro to define message object by passing scope in constructor.
* This should be used in the same source file where scope was defined.
* The scope object should be defined before it is used.
**/
#define TRACE_SCOPE(scope) TraceMessage _messager( _##scope )
/**
* \brief Use this macro to log Debug priority messages in logging target (file or remote host)
**/
#define TRACE_DBG(...) if (_messager.isDbgEnabled()) _messager.logMessage( NETrace::PrioDebug , __VA_ARGS__ )
/**
* \brief Use this macro to log Information priority messages in logging target (file or remote host)
**/
#define TRACE_INFO(...) if (_messager.isInfoEnabled()) _messager.logMessage( NETrace::PrioInfo , __VA_ARGS__ )
/**
* \brief Use this macro to log Warning priority messages in logging target (file or remote host)
**/
#define TRACE_WARN(...) if (_messager.isWarnEnabled()) _messager.logMessage( NETrace::PrioWarning , __VA_ARGS__ )
/**
* \brief Use this macro to log Error priority messages in logging target (file or remote host)
**/
#define TRACE_ERR(...) if (_messager.isErrEnabled()) _messager.logMessage( NETrace::PrioError , __VA_ARGS__ )
/**
* \brief Use this macro to log Fatal Error priority messages in logging target (file or remote host)
**/
#define TRACE_FATAL(...) if (_messager.isFatalEnabled()) _messager.logMessage( NETrace::PrioFatal , __VA_ARGS__ )
/**
* \brief Use this macro to define global scope and global message object.
* There can be only one global scope defined in the every single source file.
* Call global tracing to use global scope. The global scope is used to make
* output generic messages withing single source.
**/
#define GLOBAL_TRACE_SCOPE(scope) static TraceMessage & _getGlobalScope( void ) \
{ \
static TraceScope _##scope(#scope); \
static TraceMessage _messager(_##scope); \
static bool isActivated { false }; \
if (isActivated == false) \
{ \
NETrace::activateScope( _##scope ); \
isActivated = true; \
} \
return _messager; \
}
/**
* \brief Use this macro to log Debug priority messages in logging target (file or remote host).
* This macro will use global scope for logging. There can be only one global scope
* per source file defined.
**/
#define GLOBAL_DBG(...) _getGlobalScope().logDebug( __VA_ARGS__ )
/**
* \brief Use this macro to log Information priority messages in logging target (file or remote host)
* This macro will use global scope for logging. There can be only one global scope
* per source file defined.
**/
#define GLOBAL_INFO(...) _getGlobalScope().logInfo( __VA_ARGS__ )
/**
* \brief Use this macro to log Warning priority messages in logging target (file or remote host)
* This macro will use global scope for logging. There can be only one global scope
* per source file defined.
**/
#define GLOBAL_WARN(...) _getGlobalScope().logWarning( __VA_ARGS__ )
/**
* \brief Use this macro to log Error priority messages in logging target (file or remote host)
* This macro will use global scope for logging. There can be only one global scope
* per source file defined.
**/
#define GLOBAL_ERR(...) _getGlobalScope().logError( __VA_ARGS__ )
/**
* \brief Use this macro to log Fatal Error priority messages in logging target (file or remote host)
* This macro will use global scope for logging. There can be only one global scope
* per source file defined.
**/
#define GLOBAL_FATAL(...) _getGlobalScope().logFatal( __VA_ARGS__ )
#else // !AREG_LOGS
//////////////////////////////////////////////////////////////////////////
// if AREG_LOGS is not defined, disable priorities
//////////////////////////////////////////////////////////////////////////
//!< Priority to log everything
#define PRIO_LOG_ALL 0
//!< Priority to log info, warnings, error and fatal
#define PRIO_INFO 0
//!< Priority to log warnings, error and fatal
#define PRIO_WARNING 0
//!< Priority to log error and fatal
#define PRIO_ERROR 0
//!< Priority to log only fatal
#define PRIO_FATAL 0
//!< Unset logging scopes in priorities
#define PRIO_NOSCOPES(x) 0
//!< No logging
#define PRIO_NOLOGS 0
/**
* \brief Always returns true
**/
#define SCOPE_PRIORITY_CHANGE(scope, prio) ((3-2) > 0)
/**
* \brief Always returns 'NETrace::eLogPriority::PrioInvalid'
**/
#define SCOPE_PRIORITY_GET(scope) static_cast<unsigned int>(NETrace::eLogPriority::PrioInvalid)
//////////////////////////////////////////////////////////////////////////
// if AREG_LOG is not defined
//////////////////////////////////////////////////////////////////////////
/**
* \brief If !AREG_LOGS, returns true, makes no effect
**/
#define IS_TRACE_STARTED() ((3-2) < 0)
/**
* \brief Returns true if logging is enabled
**/
#define IS_LOG_ENABLED() ((3-2) < 0)
/**
* \brief If !AREG_LOGS, returns true, makes no effect
**/
#define TRACER_START_LOGGING(configFile) ((3-2) < 0)
/**
* \brief If !AREG_LOGS, returns true, makes no effect
**/
#define TRACER_FORCE_LOGGING() ((3-2) < 0)
/**
* \brief If !AREG_LOGS, returns true, makes no effect
**/
#define TRACER_CONFIGURE_AND_START(configFile) ((3-2) < 0)
/**
* \brief If !AREG_LOGS is zero, does nothing
**/
#define TRACER_STOP_LOGGING() {}
/**
* \brief If !AREG_LOGS is zero, does nothing, no trace scope is declared.
**/
#define DEF_TRACE_SCOPE(scope)
/**
* \brief If !AREG_LOGS is zero, does nothing, no logging message is created.
**/
#define TRACE_SCOPE(scope)
/**
* \brief If !AREG_LOGS, does nothing, all parameters are ignored.
**/
#define TRACE_DBG(...)
/**
* \brief If !AREG_LOGS, does nothing, all parameters are ignored.
**/
#define TRACE_INFO(...)
/**
* \brief If !AREG_LOGS, does nothing, all parameters are ignored.
**/
#define TRACE_WARN(...)
/**
* \brief If !AREG_LOGS, does nothing, all parameters are ignored.
**/
#define TRACE_ERR(...)
/**
* \brief If !AREG_LOGS, does nothing, all parameters are ignored.
**/
#define TRACE_FATAL(...)
/**
* \brief If !AREG_LOGS, does nothing, no global scope is initialized.
**/
#define GLOBAL_TRACE_SCOPE(scope)
/**
* \brief If !AREG_LOGS, does nothing, all parameters are ignored.
**/
#define GLOBAL_DBG(...)
/**
* \brief If !AREG_LOGS, does nothing, all parameters are ignored.
**/
#define GLOBAL_INFO(...)
/**
* \brief If !AREG_LOGS, does nothing, all parameters are ignored.
**/
#define GLOBAL_WARN(...)
/**
* \brief If !AREG_LOGS, does nothing, all parameters are ignored.
**/
#define GLOBAL_ERR(...)
/**
* \brief If !AREG_LOGS, does nothing, all parameters are ignored.
**/
#define GLOBAL_FATAL(...)
#endif // AREG_LOGS
#endif // AREG_TRACE_GETRACE_H