allow logger to (left)truncate long file and func names
This commit is contained in:
@ -24,6 +24,9 @@ int _mgos_timers = 0;
|
|||||||
|
|
||||||
int log_print_prefix(enum cs_log_level l, const char *func, const char *file) {
|
int log_print_prefix(enum cs_log_level l, const char *func, const char *file) {
|
||||||
char ll_str[6];
|
char ll_str[6];
|
||||||
|
char ll_file[31];
|
||||||
|
char ll_func[41];
|
||||||
|
size_t offset=0;
|
||||||
|
|
||||||
switch(l) {
|
switch(l) {
|
||||||
case LL_ERROR:
|
case LL_ERROR:
|
||||||
@ -44,7 +47,20 @@ int log_print_prefix(enum cs_log_level l, const char *func, const char *file) {
|
|||||||
default: // LL_NONE
|
default: // LL_NONE
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
printf ("%-5s %-20s %-40s| ", ll_str, file, func);
|
|
||||||
|
offset=0;
|
||||||
|
memset(ll_file, 0, sizeof(ll_file));
|
||||||
|
if (strlen(file) >= sizeof(ll_file))
|
||||||
|
offset=strlen(file)-sizeof(ll_file)+1;
|
||||||
|
strncpy(ll_file, file+offset, sizeof(ll_file)-1);
|
||||||
|
|
||||||
|
offset=0;
|
||||||
|
memset(ll_func, 0, sizeof(ll_func));
|
||||||
|
if (strlen(func) >= sizeof(ll_func))
|
||||||
|
offset=strlen(func)-sizeof(ll_func)+1;
|
||||||
|
strncpy(ll_func, func+offset, sizeof(ll_func)-1);
|
||||||
|
|
||||||
|
printf ("%-5s %-30s %-40s| ", ll_str, ll_file, ll_func);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user