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
);
51 #define LOG_ERROR(topic, fmt, ...) _logf(LOG_TOPIC_ ## topic, LOG_LEVEL_ERROR, fmt, ##__VA_ARGS__)
52 #define LOG_BUFFER_ERROR(topic, buf, size) _logBufferHex(LOG_TOPIC_ ## topic, LOG_LEVEL_ERROR, buf, size)
54 #define LOG_ERROR(...)
55 #define LOG_BUFFER_ERROR(...)
59 #define LOG_WARNING(topic, fmt, ...) _logf(LOG_TOPIC_ ## topic, LOG_LEVEL_WARNING, fmt, ##__VA_ARGS__)
60 #define LOG_BUF_WARNING(topic, buf, size) _logBufferHex(LOG_TOPIC_ ## topic, LOG_LEVEL_WARNING, buf, size)
62 #define LOG_WARNING(...)
63 #define LOG_BUF_WARNING(...)
67 #define LOG_INFO(topic, fmt, ...) _logf(LOG_TOPIC_ ## topic, LOG_LEVEL_INFO, fmt, ##__VA_ARGS__)
68 #define LOG_BUF_INFO(topic, buf, size) _logBufferHex(LOG_TOPIC_ ## topic, LOG_LEVEL_INFO, buf, size)
71 #define LOG_BUF_INFO(...)
75 #define LOG_VERBOSE(topic, fmt, ...) _logf(LOG_TOPIC_ ## topic, LOG_LEVEL_VERBOSE, fmt, ##__VA_ARGS__)
76 #define LOG_BUF_VERBOSE(topic, buf, size) _logBufferHex(LOG_TOPIC_ ## topic, LOG_LEVEL_VERBOSE, buf, size)
78 #define LOG_VERBOSE(...)
79 #define LOG_BUF_VERBOSE(...)
83 #define LOG_DEBUG(topic, fmt, ...) _logf(LOG_TOPIC_ ## topic, LOG_LEVEL_DEBUG, fmt, ##__VA_ARGS__)
84 #define LOG_BUF_DEBUG(topic, buf, size) _logBufferHex(LOG_TOPIC_ ## topic, LOG_LEVEL_DEBUG, buf, size)
86 #define LOG_DEBUG(...)
87 #define LOG_BUF_DEBUG(...)