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
| #include <stdio.h>
| #include <stdarg.h>
| #include "test_log.h"
| #include "rtc.h"
| #include "sundry.h"
|
| static long long default_get_sys_time_ms(void)
| {
| long long time_ms = 0;
| time_ms = BCD_2_HEX_U8(calendar_g.Hour) * 60 * 60 * 1000 + BCD_2_HEX_U8(calendar_g.Minute) * 60 * 1000 +
| BCD_2_HEX_U8(calendar_g.Second) * 1000;
| return time_ms;
| }
|
| static get_sys_time_ms_def s_get_sys_time_ms = default_get_sys_time_ms;
|
| void log_time_register(get_sys_time_ms_def p_get_sys_time_ms)
| {
| s_get_sys_time_ms = p_get_sys_time_ms;
| }
|
| void log_print(enum log_debug_type debug_type, const char *file, int line, const char *func, const char* fmt, ...)
| {
| #if LOG_PRINT_OPEN == 1
| va_list ap;
| char buf[LOG_BUF_SIZE] = {0};
| long long time = s_get_sys_time_ms();
|
| va_start(ap, fmt);
| vsnprintf(buf, sizeof(buf), fmt, ap);
| va_end(ap);
|
| switch(debug_type)
| {
| case DEBUG_NORMAL:
| printf("<%lld ms>[%s:%d %s] %s", time, file, line, func, buf);
| break;
| case DEBUG_WARNING:
| printf("\033[31m<%lld ms>[%s:%d %s] %s\033[0m", time, file, line, func, buf);
| break;
| case DEBUG_ERROR:
| printf("\033[32m<%lld ms>[%s:%d %s] %s\033[0m", time, file, line, func, buf);
| break;
| default:break;
| }
| #endif
|
| }
|
|