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
13class Logger {
14private:
15 explicit Logger() = default;
16 ~Logger() = default;
17
18 QueueHandle_t queue_handle = nullptr;
19 bool use_queue = false;
20
21public:
22 struct log_item {
23 esp_log_level_t level;
24 const char* tag;
25 char* message;
27 };
28
29public:
36 static Logger& get_instance() {
37 static Logger _instance;
38 return _instance;
39 }
40
49 void custom_log(esp_log_level_t level, const char* tag, const char* format, ...) const __attribute__((format(printf, 4, 5)));
50
54 void print_linefeed() const;
55
61 void switch_to_queue_logging(QueueHandle_t log_queue_handle);
62
67 void process_log_queue() const;
68};
69
70#define LOGV(format, ...) Logger::get_instance().custom_log(ESP_LOG_VERBOSE, TAG, format, ##__VA_ARGS__)
71#define LOGD(format, ...) Logger::get_instance().custom_log(ESP_LOG_DEBUG, TAG, format, ##__VA_ARGS__)
72#define LOGI(format, ...) Logger::get_instance().custom_log(ESP_LOG_INFO, TAG, format, ##__VA_ARGS__)
73#define LOGW(format, ...) Logger::get_instance().custom_log(ESP_LOG_WARN, TAG, format, ##__VA_ARGS__)
74#define LOGE(format, ...) Logger::get_instance().custom_log(ESP_LOG_ERROR, TAG, format, ##__VA_ARGS__)
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:36
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:22
bool is_linefeed
Definition logger.h:26
char * message
Definition logger.h:25
const char * tag
Definition logger.h:24
esp_log_level_t level
Definition logger.h:23