@@ -81,6 +81,7 @@ log_console_get(void)
81
81
#define COLOR_WRN MK_COLOR(COLOR_YELLOW)
82
82
#define COLOR_ERR MK_COLOR(COLOR_RED)
83
83
#define COLOR_CRI MK_INV_COLOR(COLOR_RED)
84
+ #define COLOR_MAX MK_COLOR(COLOR_BLUE)
84
85
85
86
#define COLOR_RESET CSI "0" CSE
86
87
@@ -104,6 +105,7 @@ log_module_color(uint8_t module, char *color_on, char *color_off)
104
105
#define COLOR_WRN ""
105
106
#define COLOR_ERR ""
106
107
#define COLOR_CRI ""
108
+ #define COLOR_MAX ""
107
109
#define COLOR_RESET ""
108
110
#define log_module_color (hdr , on , off )
109
111
#endif
@@ -114,6 +116,8 @@ static const char * const log_level_color[] = {
114
116
COLOR_WRN ,
115
117
COLOR_ERR ,
116
118
COLOR_CRI ,
119
+ /* Add new custom log levels here */
120
+ COLOR_MAX ,
117
121
};
118
122
119
123
static const char * const log_level_str [] = {
@@ -122,8 +126,12 @@ static const char * const log_level_str[] = {
122
126
"WRN" ,
123
127
"ERR" ,
124
128
"CRI" ,
129
+ /* Add new custom log levels here */
130
+ "MAX" ,
125
131
};
126
132
133
+ static int real_log_levels = ARRAY_SIZE (log_level_str ) - 1 ;
134
+
127
135
void
128
136
log_console_print_hdr (const struct log_entry_hdr * hdr )
129
137
{
@@ -134,6 +142,7 @@ log_console_print_hdr(const struct log_entry_hdr *hdr)
134
142
const char * module_name = NULL ;
135
143
char color [11 ] = "" ;
136
144
char color_off [6 ] = "" ;
145
+ uint8_t mapped_log_level ;
137
146
138
147
/* Find module defined in syscfg.logcfg sections */
139
148
module_name = log_module_get_name (hdr -> ue_module );
@@ -152,14 +161,15 @@ log_console_print_hdr(const struct log_entry_hdr *hdr)
152
161
} else {
153
162
image_hash_str [0 ] = 0 ;
154
163
}
155
- if (hdr -> ue_level <= LOG_LEVEL_CRITICAL ) {
164
+ if (hdr -> ue_level < real_log_levels || hdr -> ue_level == LOG_LEVEL_MAX ) {
165
+ mapped_log_level = hdr -> ue_level < real_log_levels ? hdr -> ue_level : real_log_levels ;
156
166
if (MYNEWT_VAL (LOG_CONSOLE_PRETTY_WITH_COLORS )) {
157
- strcpy (level_str_buf , log_level_color [hdr -> ue_level ]);
158
- strcat (level_str_buf , log_level_str [hdr -> ue_level ]);
167
+ strcpy (level_str_buf , log_level_color [mapped_log_level ]);
168
+ strcat (level_str_buf , log_level_str [mapped_log_level ]);
159
169
strcat (level_str_buf , COLOR_RESET );
160
170
level_str = level_str_buf ;
161
171
} else {
162
- level_str = log_level_str [hdr -> ue_level ];
172
+ level_str = log_level_str [mapped_log_level ];
163
173
}
164
174
} else {
165
175
sprintf (level_str_buf , "%-3u" , hdr -> ue_level );
0 commit comments