-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCLog.h
110 lines (101 loc) · 1.71 KB
/
CLog.h
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <signal.h>
#define DEBUG_COLOR 0
#define INFO_COLOR 1
#define WARN_COLOR 2
#define ERROR_COLOR 3
#define PANIC_COLOR 4
#define PANIC_BCKG 5
int logConfig[6] = { 4, 2, 3, 1, 7, 1 };
void textcolor(int attr, int fg, int bg)
{
char command[13];
sprintf(command, "%c[%d;%d;%dm", 0x1B, attr, fg + 30, bg + 40);
printf("%s", command);
}
void genericPrinter(char *type, const char *format, int attr, int fg, int bg, va_list args)
{
textcolor(attr, fg, bg);
printf("%s", type);
textcolor(0, -1, -1);
printf(" ");
vprintf(format, args);
printf("\n");
}
int infof(const char *format, ...)
{
va_list args;
va_start(args, format);
genericPrinter(
"INFO:",
format,
1,
logConfig[INFO_COLOR],
8,
args
);
fflush(stdout);
va_end(args);
}
int debugf(const char *format, ...)
{
va_list args;
va_start(args, format);
genericPrinter(
"DEBUG:",
format,
1,
logConfig[DEBUG_COLOR],
8,
args
);
fflush(stdout);
va_end(args);
}
int warnf(const char *format, ...)
{
va_list args;
va_start(args, format);
genericPrinter(
"WARNING:",
format,
1,
logConfig[WARN_COLOR],
8,
args
);
fflush(stdout);
va_end(args);
}
int errorf(const char *format, ...)
{
va_list args;
va_start(args, format);
genericPrinter(
"ERROR:",
format,
1,
logConfig[ERROR_COLOR],
8,
args
);
fflush(stdout);
va_end(args);
}
int panicf(const char *format, ...)
{
va_list args;
va_start(args, format);
genericPrinter(
"PANIC:",
format, 1,
logConfig[PANIC_COLOR],
logConfig[PANIC_BCKG],
args
);
fflush(stdout);
va_end(args);
raise(SIGABRT);
}