Flipper Zero Firmware
Loading...
Searching...
No Matches
log.h
Go to the documentation of this file.
1
5#pragma once
6
7#include <stdio.h>
8#include <stdint.h>
9#include <stdarg.h>
10#include <stdbool.h>
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16typedef enum {
17 FuriLogLevelDefault = 0,
18 FuriLogLevelNone = 1,
19 FuriLogLevelError = 2,
20 FuriLogLevelWarn = 3,
21 FuriLogLevelInfo = 4,
22 FuriLogLevelDebug = 5,
23 FuriLogLevelTrace = 6,
24} FuriLogLevel;
25
26#define _FURI_LOG_CLR(clr) "\033[0;" clr "m"
27#define _FURI_LOG_CLR_RESET "\033[0m"
28
29#define _FURI_LOG_CLR_BLACK "30"
30#define _FURI_LOG_CLR_RED "31"
31#define _FURI_LOG_CLR_GREEN "32"
32#define _FURI_LOG_CLR_BROWN "33"
33#define _FURI_LOG_CLR_BLUE "34"
34#define _FURI_LOG_CLR_PURPLE "35"
35
36#define _FURI_LOG_CLR_E _FURI_LOG_CLR(_FURI_LOG_CLR_RED)
37#define _FURI_LOG_CLR_W _FURI_LOG_CLR(_FURI_LOG_CLR_BROWN)
38#define _FURI_LOG_CLR_I _FURI_LOG_CLR(_FURI_LOG_CLR_GREEN)
39#define _FURI_LOG_CLR_D _FURI_LOG_CLR(_FURI_LOG_CLR_BLUE)
40#define _FURI_LOG_CLR_T _FURI_LOG_CLR(_FURI_LOG_CLR_PURPLE)
41
42typedef void (*FuriLogHandlerCallback)(const uint8_t* data, size_t size, void* context);
43
44typedef struct {
45 FuriLogHandlerCallback callback;
46 void* context;
48
50void furi_log_init(void);
51
59
67
73void furi_log_tx(const uint8_t* data, size_t size);
74
79void furi_log_puts(const char* data);
80
88void furi_log_print_format(FuriLogLevel level, const char* tag, const char* format, ...)
89 _ATTRIBUTE((__format__(__printf__, 3, 4)));
90
97void furi_log_print_raw_format(FuriLogLevel level, const char* format, ...)
98 _ATTRIBUTE((__format__(__printf__, 2, 3)));
99
104void furi_log_set_level(FuriLogLevel level);
105
110FuriLogLevel furi_log_get_level(void);
111
119bool furi_log_level_to_string(FuriLogLevel level, const char** str);
120
128bool furi_log_level_from_string(const char* str, FuriLogLevel* level);
129
136#define FURI_LOG_E(tag, format, ...) \
137 furi_log_print_format(FuriLogLevelError, tag, format, ##__VA_ARGS__)
138#define FURI_LOG_W(tag, format, ...) \
139 furi_log_print_format(FuriLogLevelWarn, tag, format, ##__VA_ARGS__)
140#define FURI_LOG_I(tag, format, ...) \
141 furi_log_print_format(FuriLogLevelInfo, tag, format, ##__VA_ARGS__)
142#define FURI_LOG_D(tag, format, ...) \
143 furi_log_print_format(FuriLogLevelDebug, tag, format, ##__VA_ARGS__)
144#define FURI_LOG_T(tag, format, ...) \
145 furi_log_print_format(FuriLogLevelTrace, tag, format, ##__VA_ARGS__)
146
152#define FURI_LOG_RAW_E(format, ...) \
153 furi_log_print_raw_format(FuriLogLevelError, format, ##__VA_ARGS__)
154#define FURI_LOG_RAW_W(format, ...) \
155 furi_log_print_raw_format(FuriLogLevelWarn, format, ##__VA_ARGS__)
156#define FURI_LOG_RAW_I(format, ...) \
157 furi_log_print_raw_format(FuriLogLevelInfo, format, ##__VA_ARGS__)
158#define FURI_LOG_RAW_D(format, ...) \
159 furi_log_print_raw_format(FuriLogLevelDebug, format, ##__VA_ARGS__)
160#define FURI_LOG_RAW_T(format, ...) \
161 furi_log_print_raw_format(FuriLogLevelTrace, format, ##__VA_ARGS__)
162
163#ifdef __cplusplus
164}
165#endif
bool furi_log_remove_handler(FuriLogHandler handler)
Remove log TX callback.
Definition log.c:67
void furi_log_puts(const char *data)
Transmit data through log IO callbacks.
Definition log.c:105
void furi_log_print_format(FuriLogLevel level, const char *tag, const char *format,...) _ATTRIBUTE((__format__(__printf__
Print log record.
void void furi_log_print_raw_format(FuriLogLevel level, const char *format,...) _ATTRIBUTE((__format__(__printf__
Print log record.
void furi_log_tx(const uint8_t *data, size_t size)
Transmit data through log IO callbacks.
Definition log.c:88
bool furi_log_add_handler(FuriLogHandler handler)
Add log TX callback.
Definition log.c:41
void furi_log_init(void)
Initialize logging.
Definition log.c:34
bool furi_log_level_to_string(FuriLogLevel level, const char **str)
Log level to string.
Definition log.c:193
bool furi_log_level_from_string(const char *str, FuriLogLevel *level)
Log level from string.
Definition log.c:203
FuriLogLevel furi_log_get_level(void)
Get log level.
Definition log.c:189
void void void furi_log_set_level(FuriLogLevel level)
Set log level.
Definition log.c:180
Definition log.h:44