logging.h
1.79 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
60
61
#ifndef LOGGING_H
#define LOGGING_H
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define _ERROR_ "\033[31m"
#define _DEBUG_ "\033[30m"
#define _WARN_ "\033[33m"
#define _INFO_ "\033[32m"
#define _END_ "\033[0m"
#define LOG_FILE "vlibras_user/vlibras-core/log/log"
namespace util {
enum logLevel { _QUIET = 1 , _ERROR, _WARNING, _INFO, _DEBUG};
class Logging {
public:
static Logging* instance();
logLevel getLevel();
void setLevel(logLevel level);
void writeLog(const char* logMsg);
private:
Logging(){};
Logging(Logging const&){};
Logging& operator=(Logging const&){};
static Logging* l_instance;
static logLevel l_level;
FILE* l_file;
char* getTime();
};
#define PRINTL(level, format, ... ) { \
logLevel llevel; \
llevel = Logging::instance()->getLevel(); \
if(level <= llevel){ \
switch(level){ \
case _DEBUG: \
fprintf(stdout, _DEBUG_"%s::%s<%d>: "_END_ format, __FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__); \
break; \
case _INFO: \
fprintf(stdout, _INFO_"%s::%s<%d>: "_END_ format, __FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__); \
break; \
case _WARNING: \
fprintf(stdout, _WARN_"%s::%s<%d>: "_END_ format, __FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__); \
break; \
case _ERROR: \
fprintf(stderr, _ERROR_"%s::%s<%d>: "_END_ format, __FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__); \
break; \
} \
} \
}//fim da função PRINTL
}
#endif /* LOGGING_H */