9 #include "config/parameter_group.h"
11 #include "common/utils.h"
13 // Log levels. Defined as preprocessor constants instead of
14 // a number to allow compile-time comparisons.
15 #define LOG_LEVEL_ERROR 0
16 #define LOG_LEVEL_WARNING 1
17 #define LOG_LEVEL_INFO 2
18 #define LOG_LEVEL_VERBOSE 3
19 #define LOG_LEVEL_DEBUG 4
22 LOG_TOPIC_SYSTEM
, // 0, mask = 1
23 LOG_TOPIC_GYRO
, // 1, mask = 2
24 LOG_TOPIC_BARO
, // 2, mask = 4
25 LOG_TOPIC_PITOT
, // 3, mask = 8
26 LOG_TOPIC_PWM
, // 4, mask = 16
27 LOG_TOPIC_TIMER
, // 5, mask = 32
28 LOG_TOPIC_IMU
, // 6, mask = 64
29 LOG_TOPIC_TEMPERATURE
, // 7, mask = 128
30 LOG_TOPIC_POS_ESTIMATOR
, // 8, mask = 256
31 LOG_TOPIC_VTX
, // 9, mask = 512
32 LOG_TOPIC_OSD
, // 10, mask = 1024
37 STATIC_ASSERT(LOG_TOPIC_COUNT
< 32, too_many_log_topics
);
39 typedef struct logConfig_s
{
40 uint8_t level
; // from LOG_LEVEL_ constants. All messages equal or below this verbosity level are printed.
41 uint32_t topics
; // All messages with topics in this bitmask (1 << topic) will be printed regardless of their level.
44 PG_DECLARE(logConfig_t
, logConfig
);
47 void _logf(logTopic_e topic
, unsigned level
, const char *fmt
, ...) __attribute__ ((format (printf
, 3, 4)));
48 void _logBufferHex(logTopic_e topic
, unsigned level
, const void *buffer
, size_t size
);
50 // LOG_* macro definitions
52 #if !defined(LOG_LEVEL_MAXIMUM)
53 #define LOG_LEVEL_MAXIMUM LOG_LEVEL_DEBUG
56 #if defined(USE_LOG) && LOG_LEVEL_MAXIMUM >= LOG_LEVEL_ERROR
57 #define LOG_E(topic, fmt, ...) _logf(LOG_TOPIC_ ## topic, LOG_LEVEL_ERROR, fmt, ##__VA_ARGS__)
58 #define LOG_BUFFER_E(topic, buf, size) _logBufferHex(LOG_TOPIC_ ## topic, LOG_LEVEL_ERROR, buf, size)
61 #define LOG_BUFFER_E(...)
64 #if defined(USE_LOG) && LOG_LEVEL_MAXIMUM >= LOG_LEVEL_WARNING
65 #define LOG_W(topic, fmt, ...) _logf(LOG_TOPIC_ ## topic, LOG_LEVEL_WARNING, fmt, ##__VA_ARGS__)
66 #define LOG_BUF_W(topic, buf, size) _logBufferHex(LOG_TOPIC_ ## topic, LOG_LEVEL_WARNING, buf, size)
69 #define LOG_BUF_W(...)
72 #if defined(USE_LOG) && LOG_LEVEL_MAXIMUM >= LOG_LEVEL_INFO
73 #define LOG_I(topic, fmt, ...) _logf(LOG_TOPIC_ ## topic, LOG_LEVEL_INFO, fmt, ##__VA_ARGS__)
74 #define LOG_BUF_I(topic, buf, size) _logBufferHex(LOG_TOPIC_ ## topic, LOG_LEVEL_INFO, buf, size)
77 #define LOG_BUF_I(...)
80 #if defined(USE_LOG) && LOG_LEVEL_MAXIMUM >= LOG_LEVEL_VERBOSE
81 #define LOG_V(topic, fmt, ...) _logf(LOG_TOPIC_ ## topic, LOG_LEVEL_VERBOSE, fmt, ##__VA_ARGS__)
82 #define LOG_BUF_V(topic, buf, size) _logBufferHex(LOG_TOPIC_ ## topic, LOG_LEVEL_VERBOSE, buf, size)
85 #define LOG_BUF_V(...)
88 #if defined(USE_LOG) && LOG_LEVEL_MAXIMUM >= LOG_LEVEL_DEBUG
89 #define LOG_D(topic, fmt, ...) _logf(LOG_TOPIC_ ## topic, LOG_LEVEL_DEBUG, fmt, ##__VA_ARGS__)
90 #define LOG_BUF_D(topic, buf, size) _logBufferHex(LOG_TOPIC_ ## topic, LOG_LEVEL_DEBUG, buf, size)
93 #define LOG_BUF_D(...)