2021-04-30 14:20:33 +03:00
|
|
|
#include "log.h"
|
|
|
|
#include "check.h"
|
2022-06-20 17:54:48 +03:00
|
|
|
#include "mutex.h"
|
2021-05-11 11:29:44 +03:00
|
|
|
#include <cmsis_os2.h>
|
2022-01-05 19:10:18 +03:00
|
|
|
#include <furi_hal.h>
|
2021-04-30 14:20:33 +03:00
|
|
|
|
2021-12-15 01:39:59 +03:00
|
|
|
#define FURI_LOG_LEVEL_DEFAULT FuriLogLevelInfo
|
|
|
|
|
2021-04-30 14:20:33 +03:00
|
|
|
typedef struct {
|
|
|
|
FuriLogLevel log_level;
|
2021-11-21 18:17:43 +03:00
|
|
|
FuriLogPuts puts;
|
2021-04-30 14:20:33 +03:00
|
|
|
FuriLogTimestamp timetamp;
|
2021-05-11 11:29:44 +03:00
|
|
|
osMutexId_t mutex;
|
2021-04-30 14:20:33 +03:00
|
|
|
} FuriLogParams;
|
|
|
|
|
|
|
|
static FuriLogParams furi_log;
|
|
|
|
|
|
|
|
void furi_log_init() {
|
|
|
|
// Set default logging parameters
|
2021-12-15 01:39:59 +03:00
|
|
|
furi_log.log_level = FURI_LOG_LEVEL_DEFAULT;
|
2021-11-21 18:17:43 +03:00
|
|
|
furi_log.puts = furi_hal_console_puts;
|
2022-03-30 18:23:40 +03:00
|
|
|
furi_log.timetamp = furi_hal_get_tick;
|
2021-05-11 11:29:44 +03:00
|
|
|
furi_log.mutex = osMutexNew(NULL);
|
2021-04-30 14:20:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void furi_log_print(FuriLogLevel level, const char* format, ...) {
|
2021-11-21 18:17:43 +03: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 11:29:44 +03:00
|
|
|
osMutexRelease(furi_log.mutex);
|
2021-04-30 14:20:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void furi_log_set_level(FuriLogLevel level) {
|
2021-12-15 01:39:59 +03:00
|
|
|
if(level == FuriLogLevelDefault) {
|
|
|
|
level = FURI_LOG_LEVEL_DEFAULT;
|
|
|
|
}
|
2021-04-30 14:20:33 +03:00
|
|
|
furi_log.log_level = level;
|
|
|
|
}
|
|
|
|
|
|
|
|
FuriLogLevel furi_log_get_level(void) {
|
|
|
|
return furi_log.log_level;
|
|
|
|
}
|
|
|
|
|
2021-11-21 18:17:43 +03:00
|
|
|
void furi_log_set_puts(FuriLogPuts puts) {
|
|
|
|
furi_assert(puts);
|
|
|
|
furi_log.puts = puts;
|
2021-04-30 14:20:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void furi_log_set_timestamp(FuriLogTimestamp timestamp) {
|
|
|
|
furi_assert(timestamp);
|
|
|
|
furi_log.timetamp = timestamp;
|
|
|
|
}
|