logging.h
2.21 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* \file logging.h
*
* \author Wesnydy Lima Ribeiro <wesnydy@lavid.ufpb.br>
* \date 2015
*/
#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};
/** \brief Classe responsável pelo log exibido no terminal.
*
* \headerfile util/src/include/logging.h
*/
class Logging {
public:
static Logging* instance();
/** Retorna o nível de log selecionado.
*
* \return O nível de log.
*/
logLevel getLevel();
/** Seta o nível de log, no terminal. */
void setLevel(logLevel level);
/** Escreve o log em um arquivo.
*
* \param logMsg A mensagem do log.
*/
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 */