Logging improvements and C++23 (#206)

- Improved logging code by splitting functionality up into different files
- Set C++23 as new standard (it was already the implied standard due to some code, but now it's explicit)
This commit is contained in:
Ken Van Hoeylandt
2025-02-06 22:55:51 +01:00
committed by GitHub
parent 6337458992
commit 88b3bfbe3e
13 changed files with 175 additions and 164 deletions
+8 -52
View File
@@ -4,13 +4,6 @@
#include <array>
#include <memory>
#ifdef ESP_PLATFORM
#include <esp_log.h>
#else
#include <cstdarg>
#include <cstdio>
#endif
#if not defined(ESP_PLATFORM) or (defined(CONFIG_SPIRAM_USE_MALLOC) && CONFIG_SPIRAM_USE_MALLOC == 1)
#define TT_LOG_ENTRY_COUNT 200
#define TT_LOG_MESSAGE_SIZE 128
@@ -19,17 +12,15 @@
#define TT_LOG_MESSAGE_SIZE 50
#endif
namespace tt {
#ifdef ESP_PLATFORM
#include "LogEsp.h"
#else
#include "LogSimulator.h"
#endif
/** Used for log output filtering */
enum class LogLevel {
None, /*!< No log output */
Error, /*!< Critical errors, software module can not recover on its own */
Warning, /*!< Error conditions from which recovery measures have been taken */
Info, /*!< Information messages which describe normal flow of events */
Debug, /*!< Extra information which is not necessary for normal use (values, pointers, sizes, etc). */
Verbose /*!< Bigger chunks of debugging information, or frequent messages which can potentially flood the output. */
};
#include "LogCommon.h"
namespace tt {
struct LogEntry {
LogLevel level = LogLevel::None;
@@ -43,38 +34,3 @@ struct LogEntry {
std::unique_ptr<std::array<LogEntry, TT_LOG_ENTRY_COUNT>> copyLogEntries(std::size_t& outIndex);
} // namespace tt
#ifdef ESP_PLATFORM
#define TT_LOG_E(tag, format, ...) \
ESP_LOGE(tag, format, ##__VA_ARGS__)
#define TT_LOG_W(tag, format, ...) \
ESP_LOGW(tag, format, ##__VA_ARGS__)
#define TT_LOG_I(tag, format, ...) \
ESP_LOGI(tag, format, ##__VA_ARGS__)
#define TT_LOG_D(tag, format, ...) \
ESP_LOGD(tag, format, ##__VA_ARGS__)
#define TT_LOG_V(tag, format, ...) \
ESP_LOGV(tag, format, ##__VA_ARGS__)
#else
namespace tt {
void log(LogLevel level, const char* tag, const char* format, ...);
} // namespace
#define TT_LOG_E(tag, format, ...) \
tt::log(tt::LogLevel::Error, tag, format, ##__VA_ARGS__)
#define TT_LOG_W(tag, format, ...) \
tt::log(tt::LogLevel::Warning, tag, format, ##__VA_ARGS__)
#define TT_LOG_I(tag, format, ...) \
tt::log(tt::LogLevel::Info, tag, format, ##__VA_ARGS__)
#define TT_LOG_D(tag, format, ...) \
tt::log(tt::LogLevel::Debug, tag, format, ##__VA_ARGS__)
#define TT_LOG_V(tag, format, ...) \
tt::log(tt::LogLevel::Trace, tag, format, ##__VA_ARGS__)
#endif // ESP_PLATFORM
@@ -0,0 +1,15 @@
#pragma once
namespace tt {
/** Used for log output filtering */
enum class LogLevel : int {
None = 0, /*!< No log output */
Error, /*!< Critical errors, software module can not recover on its own */
Warning, /*!< Error conditions from which recovery measures have been taken */
Info, /*!< Information messages which describe normal flow of events */
Debug, /*!< Extra information which is not necessary for normal use (values, pointers, sizes, etc). */
Verbose /*!< Bigger chunks of debugging information, or frequent messages which can potentially flood the output. */
};
}
+18
View File
@@ -0,0 +1,18 @@
#pragma once
#ifdef ESP_PLATFORM
#include <esp_log.h>
#define TT_LOG_E(tag, format, ...) \
ESP_LOGE(tag, format, ##__VA_ARGS__)
#define TT_LOG_W(tag, format, ...) \
ESP_LOGW(tag, format, ##__VA_ARGS__)
#define TT_LOG_I(tag, format, ...) \
ESP_LOGI(tag, format, ##__VA_ARGS__)
#define TT_LOG_D(tag, format, ...) \
ESP_LOGD(tag, format, ##__VA_ARGS__)
#define TT_LOG_V(tag, format, ...) \
ESP_LOGV(tag, format, ##__VA_ARGS__)
#endif // ESP_PLATFORM
@@ -0,0 +1,27 @@
#pragma once
#ifndef ESP_PLATFORM
#include "LogCommon.h"
#include <cstdarg>
#include <cstdio>
namespace tt {
void log(LogLevel level, const char* tag, const char* format, ...);
} // namespace
#define TT_LOG_E(tag, format, ...) \
tt::log(tt::LogLevel::Error, tag, format, ##__VA_ARGS__)
#define TT_LOG_W(tag, format, ...) \
tt::log(tt::LogLevel::Warning, tag, format, ##__VA_ARGS__)
#define TT_LOG_I(tag, format, ...) \
tt::log(tt::LogLevel::Info, tag, format, ##__VA_ARGS__)
#define TT_LOG_D(tag, format, ...) \
tt::log(tt::LogLevel::Debug, tag, format, ##__VA_ARGS__)
#define TT_LOG_V(tag, format, ...) \
tt::log(tt::LogLevel::Trace, tag, format, ##__VA_ARGS__)
#endif // ESP_PLATFORM