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
|
#pragma once
#include "debug.h"
/**
* Debug level, as set via `DBGOUT` environment variable.
*/
enum ETraceLevel: ui8 {
TRACE_ERR = 1,
TRACE_WARN = 2,
TRACE_NOTICE = 3,
TRACE_INFO = 4,
TRACE_DEBUG = 5,
TRACE_DETAIL = 6,
TRACE_VERBOSE = 7
};
#if !defined(NDEBUG) && !defined(Y_ENABLE_TRACE)
#define Y_ENABLE_TRACE
#endif
#ifdef Y_ENABLE_TRACE
/**
* Writes the given data into standard debug stream if current debug level set
* via `DBGOUT` environment variable permits it.
*
* Does nothing in release builds unless `Y_ENABLE_TRACE` is defined.
*
* Example usage:
* @code
* Y_DBGTRACE(DEBUG, "Advance from " << node1 << " to " << node2);
* @endcode
*
* @param elevel Debug level of this trace command, e.g.
* `WARN` or `DEBUG`. Basically a suffix of
* one of the values of `ETraceLevel` enum.
* @param args Argument chain to be written out into
* standard debug stream, joined with `<<`
* operator.
* @see ETraceLevel
*/
#define Y_DBGTRACE(elevel, args) Y_DBGTRACE0(int(TRACE_##elevel), args)
#define Y_DBGTRACE0(level, args) \
do \
if ((level) <= StdDbgLevel()) { \
StdDbgStream() << args << Endl; \
} \
while (false)
#else
#define Y_DBGTRACE(elevel, args) \
do { \
} while (false)
#define Y_DBGTRACE0(level, args) \
do { \
} while (false)
#endif
|