Boboter
Loading...
Searching...
No Matches
logger.h
Go to the documentation of this file.
1
7
8#pragma once
9
10#include <esp_log.h>
11#include <freertos/FreeRTOS.h>
12#include "include/flags.h"
13
14class Logger {
15private:
16 explicit Logger() = default;
17 ~Logger() = default;
18
19 QueueHandle_t queue_handle = nullptr;
20 bool use_queue = false;
21
22public:
23 struct log_item {
24 esp_log_level_t level;
25 const char* tag;
26 char* message;
28 };
29
30public:
37 static Logger& get_instance() {
38 static Logger _instance;
39 return _instance;
40 }
41
50 void custom_log(esp_log_level_t level, const char* tag, const char* format, ...) const __attribute__((format(printf, 4, 5)));
51
55 void print_linefeed() const;
56
62 void switch_to_queue_logging(QueueHandle_t log_queue_handle);
63
68 void process_log_queue() const;
69};
70
79#define LOGV(format, ...) do { \
80 if constexpr (Flags::LOWEST_LOG_LEVEL >= ESP_LOG_VERBOSE) { \
81 if constexpr (Flags::ENABLED_VERBOSE_LOG_SOURCES & LOG_SOURCE) { \
82 Logger::get_instance().custom_log(ESP_LOG_VERBOSE, TAG, format, ##__VA_ARGS__); \
83 } \
84 } \
85} while (0)
86
94#define LOGD(format, ...) do { \
95 if constexpr (Flags::LOWEST_LOG_LEVEL >= ESP_LOG_DEBUG) { \
96 Logger::get_instance().custom_log(ESP_LOG_DEBUG, TAG, format, ##__VA_ARGS__); \
97 } \
98} while (0)
99
107#define LOGI(format, ...) do { \
108 if constexpr (Flags::LOWEST_LOG_LEVEL >= ESP_LOG_INFO) { \
109 Logger::get_instance().custom_log(ESP_LOG_INFO, TAG, format, ##__VA_ARGS__); \
110 } \
111} while (0)
112
120#define LOGW(format, ...) do { \
121 if constexpr (Flags::LOWEST_LOG_LEVEL >= ESP_LOG_WARN) { \
122 Logger::get_instance().custom_log(ESP_LOG_WARN, TAG, format, ##__VA_ARGS__); \
123 } \
124} while (0)
125
133#define LOGE(format, ...) do { \
134 if constexpr (Flags::LOWEST_LOG_LEVEL >= ESP_LOG_ERROR) { \
135 Logger::get_instance().custom_log(ESP_LOG_ERROR, TAG, format, ##__VA_ARGS__); \
136 } \
137} while (0)
void custom_log(esp_log_level_t level, const char *tag, const char *format,...) const __attribute__((format(printf
Either directly invokes render_to_console (real mode) or sends to the queue (queue mode).
Definition logger.cpp:40
static Logger & get_instance()
Returns a reference to the static logger instance.
Definition logger.h:37
void switch_to_queue_logging(QueueHandle_t log_queue_handle)
Switches the logger's mode to queue logging.
Definition logger.cpp:74
void void print_linefeed() const
Prints a \n in the currently selected mode.
Definition logger.cpp:63
void process_log_queue() const
Processes all entries in the log queue.
Definition logger.cpp:79
Definition logger.h:23
bool is_linefeed
Definition logger.h:27
char * message
Definition logger.h:26
const char * tag
Definition logger.h:25
esp_log_level_t level
Definition logger.h:24