-
Notifications
You must be signed in to change notification settings - Fork 2
/
log.h
95 lines (82 loc) · 1.92 KB
/
log.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
#ifndef _ZIC_LOG_H_
#define _ZIC_LOG_H_
#include <string>
#include <stdarg.h>
#define ZIC_LOG_DEBUG 1
#define ZIC_LOG_INFO 2
#define ZIC_LOG_WARN 3
#define ZIC_LOG_ERROR 4
#ifndef ZIC_LOG_LEVEL
#define ZIC_LOG_LEVEL ZIC_LOG_DEBUG
#endif
void showLogLevel() {
if (ZIC_LOG_LEVEL == ZIC_LOG_DEBUG)
printf("log level DEBUG\n");
if (ZIC_LOG_LEVEL == ZIC_LOG_INFO)
printf("log level INFO\n");
if (ZIC_LOG_LEVEL == ZIC_LOG_WARN)
printf("log level WARN\n");
if (ZIC_LOG_LEVEL == ZIC_LOG_ERROR)
printf("log level ERROR\n");
}
void logDebug(std::string message) {
#if ZIC_LOG_LEVEL <= ZIC_LOG_DEBUG
printf("[debug] %s\n", message.c_str());
#endif
}
void logDebug(const char* message, ...) {
#if ZIC_LOG_LEVEL <= ZIC_LOG_DEBUG
va_list args;
va_start(args, message);
printf("[debug] ");
vprintf(message, args);
printf("\n");
va_end(args);
#endif
}
void logInfo(std::string message) {
#if ZIC_LOG_LEVEL <= ZIC_LOG_INFO
printf("[info] %s\n", message.c_str());
#endif
}
void logInfo(const char* message, ...) {
#if ZIC_LOG_LEVEL <= ZIC_LOG_INFO
va_list args;
va_start(args, message);
printf("[info] ");
vprintf(message, args);
printf("\n");
va_end(args);
#endif
}
void logWarn(std::string message) {
#if ZIC_LOG_LEVEL <= ZIC_LOG_WARN
printf("[warn] %s\n", message.c_str());
#endif
}
void logWarn(const char* message, ...) {
#if ZIC_LOG_LEVEL <= ZIC_LOG_WARN
va_list args;
va_start(args, message);
printf("[warn] ");
vprintf(message, args);
printf("\n");
va_end(args);
#endif
}
void logError(std::string message) {
#if ZIC_LOG_LEVEL <= ZIC_LOG_ERROR
printf("[error] %s\n", message.c_str());
#endif
}
void logError(const char* message, ...) {
#if ZIC_LOG_LEVEL <= ZIC_LOG_ERROR
va_list args;
va_start(args, message);
printf("[error] ");
vprintf(message, args);
printf("\n");
va_end(args);
#endif
}
#endif