2021-04-30 11:20:33 +00:00
|
|
|
#include "log.h"
|
|
|
|
#include "check.h"
|
2021-05-11 08:29:44 +00:00
|
|
|
#include <cmsis_os2.h>
|
2022-01-05 16:10:18 +00:00
|
|
|
#include <furi_hal.h>
|
2021-04-30 11:20:33 +00:00
|
|
|
|
2021-12-14 22:39:59 +00:00
|
|
|
#define FURI_LOG_LEVEL_DEFAULT FuriLogLevelInfo
|
|
|
|
|
2021-04-30 11:20:33 +00:00
|
|
|
typedef struct {
|
|
|
|
FuriLogLevel log_level;
|
2021-11-21 15:17:43 +00:00
|
|
|
FuriLogPuts puts;
|
2021-04-30 11:20:33 +00:00
|
|
|
FuriLogTimestamp timetamp;
|
2021-05-11 08:29:44 +00:00
|
|
|
osMutexId_t mutex;
|
2021-04-30 11:20:33 +00:00
|
|
|
} FuriLogParams;
|
|
|
|
|
|
|
|
static FuriLogParams furi_log;
|
|
|
|
|
|
|
|
void furi_log_init() {
|
|
|
|
// Set default logging parameters
|
2021-12-14 22:39:59 +00:00
|
|
|
furi_log.log_level = FURI_LOG_LEVEL_DEFAULT;
|
2021-11-21 15:17:43 +00:00
|
|
|
furi_log.puts = furi_hal_console_puts;
|
2022-03-30 15:23:40 +00:00
|
|
|
furi_log.timetamp = furi_hal_get_tick;
|
2021-05-11 08:29:44 +00:00
|
|
|
furi_log.mutex = osMutexNew(NULL);
|
2021-04-30 11:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void furi_log_print(FuriLogLevel level, const char* format, ...) {
|
2021-11-21 15:17:43 +00:00
|
|
|
if(level <= furi_log.log_level && osMutexAcquire(furi_log.mutex, osWaitForever) == osOK) {
|
|
|
|
string_t string;
|
|
|
|
|
|
|
|
// Timestamp
|
|
|
|
string_init_printf(string, "%lu ", furi_log.timetamp());
|
|
|
|
furi_log.puts(string_get_cstr(string));
|
|
|
|
string_clear(string);
|
|
|
|
|
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
|
|
|
string_init_vprintf(string, format, args);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
furi_log.puts(string_get_cstr(string));
|
|
|
|
string_clear(string);
|
|
|
|
|
2021-05-11 08:29:44 +00:00
|
|
|
osMutexRelease(furi_log.mutex);
|
2021-04-30 11:20:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void furi_log_set_level(FuriLogLevel level) {
|
2021-12-14 22:39:59 +00:00
|
|
|
if(level == FuriLogLevelDefault) {
|
|
|
|
level = FURI_LOG_LEVEL_DEFAULT;
|
|
|
|
}
|
2021-04-30 11:20:33 +00:00
|
|
|
furi_log.log_level = level;
|
|
|
|
}
|
|
|
|
|
|
|
|
FuriLogLevel furi_log_get_level(void) {
|
|
|
|
return furi_log.log_level;
|
|
|
|
}
|
|
|
|
|
2021-11-21 15:17:43 +00:00
|
|
|
void furi_log_set_puts(FuriLogPuts puts) {
|
|
|
|
furi_assert(puts);
|
|
|
|
furi_log.puts = puts;
|
2021-04-30 11:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void furi_log_set_timestamp(FuriLogTimestamp timestamp) {
|
|
|
|
furi_assert(timestamp);
|
|
|
|
furi_log.timetamp = timestamp;
|
|
|
|
}
|