dprintf.h
2.62 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
#ifndef __DPRINTF_H__
#define __DPRINTF_H__
/* A macro DEBUG_LEVEL determina o nivel de debugging
* A seguinte regra eh utilizada:
*
* DEBUG_LEVEL >= 3: Apenas DDDPRINTF serah compilada.
* DEBUG_LEVEL >= 2: DDDPRINTF E DDPRINTF serao compiladas.
* DEBUG_LEVEL >= 1: DDDPRINTF, DDPRINTF e DPRINTF serao compiladas.
* DEBUG_LEVEL == 0: Nada sera compilado. */
#include <stdio.h>
/* tamanho maximo (em bytes) do arquivo de log (1M) */
//#define TAMANHO_MAXIMO_LOG 1048576
#define TAMANHO_MAXIMO_LOG 5242880
#define _DPRINTF_ERROR "\033[30m"
#define _DPRINTF_WARN "\033[33m"
#define _DPRINTF_INFO "\033[32m"
#define _DPRINTF_FAIL "\033[31m"
#define _DPRINTF_END "\033[0m"
#define _DPRINTF_NOP(format, ...) do { } while (0)
#ifdef DEBUG_LEVEL
#if DEBUG_LEVEL & 4
#define DDDPRINTF(format, ...) { \
fprintf(stderr, \
_DPRINTF_ERROR"%s::%s [%d] -> "_DPRINTF_END format, \
__FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__); \
}
#else /* !DEBUG_LEVEL > 2 */
#define DDDPRINTF _DPRINTF_NOP
#endif /* DEBUG_LEVEL > 2 */
#if DEBUG_LEVEL & 2
#define DDPRINTF(format, ...) { \
fprintf(stderr, \
_DPRINTF_WARN"%s::%s [%d] -> "_DPRINTF_END format, \
__FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__); \
}
#else /* !DEBUG_LEVEL > 1 */
#define DDPRINTF _DPRINTF_NOP
#endif /* DEBUG_LEVEL > 1 */
#if DEBUG_LEVEL & 1
#define DPRINTF(format, ...) { \
fprintf(stderr, \
_DPRINTF_INFO"%s::%s [%d] -> "_DPRINTF_END format, \
__FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__); \
}
#else /* !DEBUG_LEVEL > 0 */
#define DPRINTF _DPRINTF_NOP
#endif /* DEBUG_LEVEL > 0 */
#if DEBUG_LEVEL & 1
#define DDDDPRINTF(format, ...) { \
fprintf(stderr, \
_DPRINTF_FAIL"%s::%s [%d] -> "_DPRINTF_END format, \
__FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__); \
}
#else /* !DEBUG_LEVEL > 0 */
#define DDDDPRINTF _DPRINTF_NOP
#endif /* DEBUG_LEVEL > 0 */
#else /* DEBUG_LEVEL */
#define DPRINTF _DPRINTF_NOP
#define DDPRINTF _DPRINTF_NOP
#define DDDPRINTF _DPRINTF_NOP
#endif /* ! DEBUG_LEVEL */
#endif /* __DPRINTF_H__ */