-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRP_Logger.cpp
More file actions
105 lines (94 loc) · 2.49 KB
/
Copy pathRP_Logger.cpp
File metadata and controls
105 lines (94 loc) · 2.49 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
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
#include "RP_Logger.h"
#include "freertos/idf_additions.h"
#include <cstdio>
int _rp_logger_log_level = RP_LOGGER_TRACE;
int _rp_logger_subsys_mask = RpLoggerSubsys::ALL;
void rp_logger_init(int level, int subsystems_to_log) {
if (!Serial) {
Serial.begin(RP_LOGGER_SERIAL_BAUDRATE);
}
_rp_logger_log_level = level;
_rp_logger_subsys_mask = subsystems_to_log;
}
static inline const char *path_to_filename(const char *path) {
const char *slash = strrchr(path, '/');
if (!slash)
slash = strrchr(path, '\\');
return slash ? slash + 1 : path;
}
static inline const char *rp_logger_level_to_string(int level) {
switch (level) {
case RP_LOGGER_MUST:
return "MUST";
case RP_LOGGER_WARN:
return "WARN";
case RP_LOGGER_INFO:
return "INFO";
case RP_LOGGER_TRACE:
return "TRACE";
default:
return "UNKNOWN";
}
}
const char *rp_logger_subsys_to_string(RpLoggerSubsys subsys) {
switch (subsys) {
case INIT:
return "INIT";
case RADIO_CMD_TRANSPORT:
return "RADIO";
case CAN_BUS:
return "CAN_BUS";
case MUTEX:
return "MUTEX";
case SERIAL_CMD_TRANSPORT:
return "SERIAL";
case CMD_HANDLER:
return "CMD_H";
case STATE_MACHINE:
return "SM";
case ADXL:
return "ADXL";
case SECONDARY_SENSORS:
return "SEC";
case GLOBAL_STORE:
return "GLB_STR";
case SD_CARD:
return "SD";
case ADC:
return "ADC";
case RESET_HANDLER:
return "RST";
case TIME_SYNC:
return "SYNC";
case ALL:
return "ALL";
default:
return "UNKNOWN";
}
}
void rp_logger_log_backend(
int level, RpLoggerSubsys subsys, const char *file, int line, const char *fmt, ...
) {
if (level > _rp_logger_log_level || (subsys & _rp_logger_subsys_mask) == 0) {
return;
}
char full_buffer[RP_LOGGER_PRINT_BUFFER_SIZE]{};
int prefix_len = snprintf(
full_buffer,
sizeof(full_buffer),
"[%lu | %-8.8s | %-5s | %-5.5s | %6.6s:%-4d]: ",
millis(),
pcTaskGetName(NULL),
rp_logger_level_to_string(level),
rp_logger_subsys_to_string(subsys),
path_to_filename(file),
line
);
if (prefix_len < sizeof(full_buffer)) {
va_list args;
va_start(args, fmt);
vsnprintf(full_buffer + prefix_len, sizeof(full_buffer) - prefix_len, fmt, args);
va_end(args);
}
puts(full_buffer);
}