mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-22 20:43:07 +00:00
[FL-3363] More descriptive error messages for the log command (#2835)
* More descriptive error messages for the log command * Log level description improvements * Log help changes Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
parent
14fc960246
commit
8bccfd6fd8
5 changed files with 83 additions and 19 deletions
|
@ -165,24 +165,23 @@ void cli_command_log_tx_callback(const uint8_t* buffer, size_t size, void* conte
|
|||
furi_stream_buffer_send(context, buffer, size, 0);
|
||||
}
|
||||
|
||||
void cli_command_log_level_set_from_string(FuriString* level) {
|
||||
if(furi_string_cmpi_str(level, "default") == 0) {
|
||||
furi_log_set_level(FuriLogLevelDefault);
|
||||
} else if(furi_string_cmpi_str(level, "none") == 0) {
|
||||
furi_log_set_level(FuriLogLevelNone);
|
||||
} else if(furi_string_cmpi_str(level, "error") == 0) {
|
||||
furi_log_set_level(FuriLogLevelError);
|
||||
} else if(furi_string_cmpi_str(level, "warn") == 0) {
|
||||
furi_log_set_level(FuriLogLevelWarn);
|
||||
} else if(furi_string_cmpi_str(level, "info") == 0) {
|
||||
furi_log_set_level(FuriLogLevelInfo);
|
||||
} else if(furi_string_cmpi_str(level, "debug") == 0) {
|
||||
furi_log_set_level(FuriLogLevelDebug);
|
||||
} else if(furi_string_cmpi_str(level, "trace") == 0) {
|
||||
furi_log_set_level(FuriLogLevelTrace);
|
||||
bool cli_command_log_level_set_from_string(FuriString* level) {
|
||||
FuriLogLevel log_level;
|
||||
if(furi_log_level_from_string(furi_string_get_cstr(level), &log_level)) {
|
||||
furi_log_set_level(log_level);
|
||||
return true;
|
||||
} else {
|
||||
printf("Unknown log level\r\n");
|
||||
printf("<log> — start logging using the current level from the system settings\r\n");
|
||||
printf("<log error> — only critical errors and other important messages\r\n");
|
||||
printf("<log warn> — non-critical errors and warnings including <log error>\r\n");
|
||||
printf("<log info> — non-critical information including <log warn>\r\n");
|
||||
printf("<log default> — the default system log level (equivalent to <log info>)\r\n");
|
||||
printf(
|
||||
"<log debug> — debug information including <log info> (may impact system performance)\r\n");
|
||||
printf(
|
||||
"<log trace> — system traces including <log debug> (may impact system performance)\r\n");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void cli_command_log(Cli* cli, FuriString* args, void* context) {
|
||||
|
@ -193,12 +192,20 @@ void cli_command_log(Cli* cli, FuriString* args, void* context) {
|
|||
bool restore_log_level = false;
|
||||
|
||||
if(furi_string_size(args) > 0) {
|
||||
cli_command_log_level_set_from_string(args);
|
||||
if(!cli_command_log_level_set_from_string(args)) {
|
||||
furi_stream_buffer_free(ring);
|
||||
return;
|
||||
}
|
||||
restore_log_level = true;
|
||||
}
|
||||
|
||||
const char* current_level;
|
||||
furi_log_level_to_string(furi_log_get_level(), ¤t_level);
|
||||
printf("Current log level: %s\r\n", current_level);
|
||||
|
||||
furi_hal_console_set_tx_callback(cli_command_log_tx_callback, ring);
|
||||
|
||||
printf("Use <log ?> to list available log levels\r\n");
|
||||
printf("Press CTRL+C to stop...\r\n");
|
||||
while(!cli_cmd_interrupt_received(cli)) {
|
||||
size_t ret = furi_stream_buffer_receive(ring, buffer, CLI_COMMAND_LOG_BUFFER_SIZE, 50);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
entry,status,name,type,params
|
||||
Version,+,34.0,,
|
||||
Version,+,34.1,,
|
||||
Header,+,applications/services/bt/bt_service/bt.h,,
|
||||
Header,+,applications/services/cli/cli.h,,
|
||||
Header,+,applications/services/cli/cli_vcp.h,,
|
||||
|
@ -1281,6 +1281,8 @@ Function,+,furi_kernel_restore_lock,int32_t,int32_t
|
|||
Function,+,furi_kernel_unlock,int32_t,
|
||||
Function,+,furi_log_get_level,FuriLogLevel,
|
||||
Function,-,furi_log_init,void,
|
||||
Function,+,furi_log_level_from_string,_Bool,"const char*, FuriLogLevel*"
|
||||
Function,+,furi_log_level_to_string,_Bool,"FuriLogLevel, const char**"
|
||||
Function,+,furi_log_print_format,void,"FuriLogLevel, const char*, const char*, ..."
|
||||
Function,+,furi_log_print_raw_format,void,"FuriLogLevel, const char*, ..."
|
||||
Function,+,furi_log_set_level,void,FuriLogLevel
|
||||
|
|
|
|
@ -1,5 +1,5 @@
|
|||
entry,status,name,type,params
|
||||
Version,+,34.0,,
|
||||
Version,+,34.1,,
|
||||
Header,+,applications/services/bt/bt_service/bt.h,,
|
||||
Header,+,applications/services/cli/cli.h,,
|
||||
Header,+,applications/services/cli/cli_vcp.h,,
|
||||
|
@ -1450,6 +1450,8 @@ Function,+,furi_kernel_restore_lock,int32_t,int32_t
|
|||
Function,+,furi_kernel_unlock,int32_t,
|
||||
Function,+,furi_log_get_level,FuriLogLevel,
|
||||
Function,-,furi_log_init,void,
|
||||
Function,+,furi_log_level_from_string,_Bool,"const char*, FuriLogLevel*"
|
||||
Function,+,furi_log_level_to_string,_Bool,"FuriLogLevel, const char**"
|
||||
Function,+,furi_log_print_format,void,"FuriLogLevel, const char*, const char*, ..."
|
||||
Function,+,furi_log_print_raw_format,void,"FuriLogLevel, const char*, ..."
|
||||
Function,+,furi_log_set_level,void,FuriLogLevel
|
||||
|
|
|
|
@ -14,6 +14,21 @@ typedef struct {
|
|||
|
||||
static FuriLogParams furi_log;
|
||||
|
||||
typedef struct {
|
||||
const char* str;
|
||||
FuriLogLevel level;
|
||||
} FuriLogLevelDescription;
|
||||
|
||||
static const FuriLogLevelDescription FURI_LOG_LEVEL_DESCRIPTIONS[] = {
|
||||
{"default", FuriLogLevelDefault},
|
||||
{"none", FuriLogLevelNone},
|
||||
{"error", FuriLogLevelError},
|
||||
{"warn", FuriLogLevelWarn},
|
||||
{"info", FuriLogLevelInfo},
|
||||
{"debug", FuriLogLevelDebug},
|
||||
{"trace", FuriLogLevelTrace},
|
||||
};
|
||||
|
||||
void furi_log_init() {
|
||||
// Set default logging parameters
|
||||
furi_log.log_level = FURI_LOG_LEVEL_DEFAULT;
|
||||
|
@ -117,3 +132,23 @@ void furi_log_set_timestamp(FuriLogTimestamp timestamp) {
|
|||
furi_assert(timestamp);
|
||||
furi_log.timestamp = timestamp;
|
||||
}
|
||||
|
||||
bool furi_log_level_to_string(FuriLogLevel level, const char** str) {
|
||||
for(size_t i = 0; i < COUNT_OF(FURI_LOG_LEVEL_DESCRIPTIONS); i++) {
|
||||
if(level == FURI_LOG_LEVEL_DESCRIPTIONS[i].level) {
|
||||
*str = FURI_LOG_LEVEL_DESCRIPTIONS[i].str;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool furi_log_level_from_string(const char* str, FuriLogLevel* level) {
|
||||
for(size_t i = 0; i < COUNT_OF(FURI_LOG_LEVEL_DESCRIPTIONS); i++) {
|
||||
if(strcmp(str, FURI_LOG_LEVEL_DESCRIPTIONS[i].str) == 0) {
|
||||
*level = FURI_LOG_LEVEL_DESCRIPTIONS[i].level;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -87,6 +88,23 @@ void furi_log_set_puts(FuriLogPuts puts);
|
|||
*/
|
||||
void furi_log_set_timestamp(FuriLogTimestamp timestamp);
|
||||
|
||||
/** Log level to string
|
||||
*
|
||||
* @param[in] level The level
|
||||
*
|
||||
* @return The string
|
||||
*/
|
||||
bool furi_log_level_to_string(FuriLogLevel level, const char** str);
|
||||
|
||||
/** Log level from string
|
||||
*
|
||||
* @param[in] str The string
|
||||
* @param level The level
|
||||
*
|
||||
* @return True if success, False otherwise
|
||||
*/
|
||||
bool furi_log_level_from_string(const char* str, FuriLogLevel* level);
|
||||
|
||||
/** Log methods
|
||||
*
|
||||
* @param tag The application tag
|
||||
|
|
Loading…
Reference in a new issue