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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
#ifdef __cplusplus
extern "C" {
#endif
#include "sapp_api.h"
#include "sapp_private_api.h"
#include "sapp_declaration.h"
#include "support/tomlc99_wrap.h"
void sapp_printf(const char *fmt, ...)
{
va_list ap;
if(sapp_global_val->cla.slient_mode != 0){
return;
}
va_start(ap, fmt);
vprintf(fmt, ap);
va_end(ap);
return;
}
void sapp_printf_colorful(int level, const char *format, ...)
{
va_list ap;
char local_log_content_buff[XATTR_SIZE_MAX];
const char *log_color_start = "";
const char *log_color_end = "";
FILE *out_fp = stdout;
va_start(ap, format);
vsnprintf(local_log_content_buff, sizeof(local_log_content_buff), format, ap);
va_end(ap);
switch(level)
{
case RLOG_LV_DEBUG:
log_color_start = "\033[33m";
log_color_end = "\033[0m";
break;
case RLOG_LV_INFO:
log_color_start = "\033[1;33m";
log_color_end = "\033[0m";
break;
case RLOG_LV_FATAL:
log_color_start = "\033[1;31;40m[Error]";
log_color_end = "\033[0m";
out_fp = stderr;
break;
default:
break;
}
fprintf(out_fp, "%s%s%s", log_color_start, local_log_content_buff, log_color_end);
return;
}
/*
print_sw, file_sw:
0:�����;
10,20,30:��level�ȼ��Ƚ��Ƿ����;
~0: ǿ�����, ���ܵ�ǰȫ��log_level�Ƕ���.
*/
void sapp_log(int level, int print_sw, int file_sw, const char *format, ...)
{
va_list ap;
char local_log_content_buff[XATTR_SIZE_MAX];
const char *log_color_start = "";
const char *log_color_end = "";
FILE *out_fp = stdout;
if(sapp_global_val->cla.slient_mode != 0){
print_sw = 0;
}
if (MESA_handle_runtime_log_level_enabled(ABBR_SAPP_LOG_HANDLE, level) == 0)
{
if((print_sw != ~0) && (file_sw != ~0)){
return;
}
}
if((0 == print_sw) && (0 == file_sw)){
return;
}
va_start(ap, format);
vsnprintf(local_log_content_buff, sizeof(local_log_content_buff), format, ap);
va_end(ap);
switch(level)
{
case RLOG_LV_DEBUG:
//log_color_start = "\033[41m";
//log_color_end = "\033[0m";
break;
case RLOG_LV_INFO:
log_color_start = "\033[32m";
log_color_end = "\033[0m";
break;
case RLOG_LV_FATAL:
log_color_start = "\033[1;31;40m[Error]";
log_color_end = "\033[0m";
out_fp = stderr;
break;
default:
break;
}
if((~0 == file_sw) || (MESA_handle_runtime_log_level_enabled(ABBR_SAPP_LOG_HANDLE, level))){
MESA_handle_runtime_log(sapp_global_val->individual_fixed.log_handle, level, (char *)"sapp", "%s", local_log_content_buff);
}
if((~0 == print_sw) || (MESA_handle_runtime_log_level_enabled(ABBR_SAPP_LOG_HANDLE, level))){
fprintf(out_fp, "%s%s%s\n", log_color_start, local_log_content_buff, log_color_end);
}
return;
}
#ifdef __cplusplus
}
#endif
|