Welcome to mirror list, hosted at ThFree Co, Russian Federation.

log.c « core « furi - github.com/ClusterM/flipperzero-firmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8cf9048556688295a6478153efaf39d70fa5c8e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "log.h"
#include "check.h"
#include "mutex.h"
#include <furi_hal.h>

#define FURI_LOG_LEVEL_DEFAULT FuriLogLevelInfo

typedef struct {
    FuriLogLevel log_level;
    FuriLogPuts puts;
    FuriLogTimestamp timetamp;
    FuriMutex* mutex;
} FuriLogParams;

static FuriLogParams furi_log;

void furi_log_init() {
    // Set default logging parameters
    furi_log.log_level = FURI_LOG_LEVEL_DEFAULT;
    furi_log.puts = furi_hal_console_puts;
    furi_log.timetamp = furi_get_tick;
    furi_log.mutex = furi_mutex_alloc(FuriMutexTypeNormal);
}

void furi_log_print(FuriLogLevel level, const char* format, ...) {
    if(level <= furi_log.log_level &&
       furi_mutex_acquire(furi_log.mutex, FuriWaitForever) == FuriStatusOk) {
        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);

        furi_mutex_release(furi_log.mutex);
    }
}

void furi_log_set_level(FuriLogLevel level) {
    if(level == FuriLogLevelDefault) {
        level = FURI_LOG_LEVEL_DEFAULT;
    }
    furi_log.log_level = level;
}

FuriLogLevel furi_log_get_level(void) {
    return furi_log.log_level;
}

void furi_log_set_puts(FuriLogPuts puts) {
    furi_assert(puts);
    furi_log.puts = puts;
}

void furi_log_set_timestamp(FuriLogTimestamp timestamp) {
    furi_assert(timestamp);
    furi_log.timetamp = timestamp;
}