1
mirror of https://github.com/DarkFlippers/unleashed-firmware.git synced 2025-12-12 04:34:43 +04: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:
Astra
2023-07-11 14:41:16 +03:00
committed by GitHub
parent 14fc960246
commit 8bccfd6fd8
5 changed files with 83 additions and 19 deletions

View File

@@ -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;
}

View File

@@ -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