-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogging.h
More file actions
59 lines (45 loc) · 1.43 KB
/
Copy pathlogging.h
File metadata and controls
59 lines (45 loc) · 1.43 KB
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
#ifndef _LOGGING_H_
#define _LOGGING_H_
#include <cstdio>
#include <cstdint>
#define LOG_CAT_ALL 0xffffffff
#define LOG_CAT_DEFAULT (1u << 31)
#define LOG_LVL_ERR 0
#define LOG_LVL_WARN 2
#define LOG_LVL_NOTICE 4
#define LOG_LVL_INFO 5
#define LOG_LVL_NOISE 6
#define SET_LOG_CAT(x) static uint32_t _file_log_cat __attribute__ ((unused)) = x
#define SET_LOG_LEVEL(x) static int _file_log_level __attribute__ ((unused)) = x
#ifdef JH_VERBOSE_LOGGING
#define LOG( fmt, ... ) fprintf( stderr, fmt "\n", ##__VA_ARGS__ )
#define LOG_ERR( fmt, ... ) fprintf( stderr, "ERROR: " fmt "\n", ##__VA_ARGS__ )
class Tracer {
public:
Tracer( int level, const char *func, const char *file, int line,
volatile uint32_t&, volatile int& file_level ) :
mLevel( level ), mFunc( func ), mFileLevel( file_level )
{
if ( mLevel <= file_level )
fprintf( stderr, "[TRACE] %s begin\n", mFunc );
}
~Tracer()
{
if ( mLevel <= mFileLevel )
fprintf( stderr, "[TRACE] %s end\n", mFunc );
}
int getLevel() { return mLevel; }
private:
int mLevel;
const char *mFunc;
volatile int& mFileLevel;
};
#define TRACE_BEGIN(level) \
Tracer _tracer( level, __PRETTY_FUNCTION__, __FILE__, __LINE__, _file_log_cat, _file_log_level )
#else // !JH_VERBOSE_LOGGING
#define LOG( fmt, ... )
#define LOG_ERR( fmt, ... ) fprintf( stderr, "ERROR: " fmt "\n", ##__VA_ARGS__ )
#define TRACE_BEGIN(x)
#endif // JH_VERBOSE_LOGGING
#define TRACE_END()
#endif // _LOGGING_H_