|
HardFOC Core
API reference
|
Advanced logging system with formatting capabilities. More...
#include <Logger.h>
Classes | |
| struct | TagLevel |
Public Member Functions | |
| bool | Initialize (const LogConfig &config=LogConfig{}) noexcept |
Initialize the logger using the platform-default BaseLogger backend (resolved via the MCU-specific logger factory). | |
| bool | Initialize (const LogConfig &config, std::unique_ptr< BaseLogger > backend) noexcept |
Initialize the logger with a caller-supplied BaseLogger. | |
| void | Deinitialize () noexcept |
| Deinitialize the logger. | |
| bool | IsInitialized () const noexcept |
| Check if logger is initialized. | |
| void | SetLogLevel (const char *tag, LogLevel level) noexcept |
| Set log level for a tag. | |
| LogLevel | GetLogLevel (const char *tag) const noexcept |
| Get log level for a tag. | |
| void | SetTagLevel (const char *tag, LogLevel level) noexcept |
| Set the minimum visible log level for messages emitted with a specific tag (e.g. throttle a noisy HAL handler during a boot self-test). | |
| void | Error (const char *tag, const char *format,...) noexcept |
| Log error message. | |
| void | Warn (const char *tag, const char *format,...) noexcept |
| Log warning message. | |
| void | Info (const char *tag, const char *format,...) noexcept |
| Log info message. | |
| void | Debug (const char *tag, const char *format,...) noexcept |
| Log debug message. | |
| void | Verbose (const char *tag, const char *format,...) noexcept |
| Log verbose message. | |
| void | Error (const char *tag, LogColor color, LogStyle style, const char *format,...) noexcept |
| Log error message with formatting. | |
| void | Warn (const char *tag, LogColor color, LogStyle style, const char *format,...) noexcept |
| Log warning message with formatting. | |
| void | Info (const char *tag, LogColor color, LogStyle style, const char *format,...) noexcept |
| Log info message with formatting. | |
| void | Debug (const char *tag, LogColor color, LogStyle style, const char *format,...) noexcept |
| Log debug message with formatting. | |
| void | Verbose (const char *tag, LogColor color, LogStyle style, const char *format,...) noexcept |
| Log verbose message with formatting. | |
| void | LogAsciiArt (const char *tag, const char *ascii_art, const AsciiArtFormat &format=AsciiArtFormat{}) noexcept |
| Log ASCII art. | |
| void | LogAsciiArt (LogLevel level, const char *tag, const char *ascii_art, const AsciiArtFormat &format=AsciiArtFormat{}) noexcept |
| Log ASCII art with log level. | |
| void | LogBanner (const char *tag, const char *ascii_art, const AsciiArtFormat &format=AsciiArtFormat{}) noexcept |
| Log ASCII art banner. | |
| void | SetConfig (const LogConfig &config) noexcept |
| Set default configuration. | |
| LogConfig | GetConfig () const noexcept |
| Get current configuration. | |
| void | EnableColors (bool enable) noexcept |
| Enable/disable colors. | |
| void | EnableEffects (bool enable) noexcept |
| Enable/disable effects. | |
| void | EnableAsciiArt (bool enable) noexcept |
| Enable/disable ASCII art support. | |
| void | Flush () noexcept |
| Flush any buffered output. | |
Static Public Member Functions | |
| static Logger & | GetInstance () noexcept |
| Get singleton instance. | |
Private Member Functions | |
| Logger () noexcept | |
| Constructor. | |
| ~Logger () noexcept | |
| Destructor. | |
| Logger (const Logger &)=delete | |
| Copy constructor (deleted) | |
| Logger & | operator= (const Logger &)=delete |
| Assignment operator (deleted) | |
| Logger (Logger &&)=delete | |
| Move constructor (deleted) | |
| Logger & | operator= (Logger &&)=delete |
| Move assignment operator (deleted) | |
| void | LogInternal (LogLevel level, const char *tag, LogColor color, LogStyle style, const char *format, va_list args) noexcept |
| Internal logging method. | |
| size_t | WriteColorPrefix (char *buf, size_t buf_size, LogColor color, LogBackground background, LogStyle style) const noexcept |
| Write ANSI color/style prefix into a buffer. | |
| void | FormatAndLogAsciiArt (const char *tag, LogLevel level, const char *ascii_art, const AsciiArtFormat &format) noexcept |
| Format and log ASCII art line-by-line without heap allocation. | |
| bool | IsLevelEnabled (LogLevel level, const char *tag) const noexcept |
| Check if log level is enabled for tag. | |
| void | DumpStatistics () const noexcept |
| Dump comprehensive logger statistics to log as INFO level. Logs internal logger statistics, configuration, and performance metrics. | |
Static Private Member Functions | |
| static size_t | WriteResetSequence (char *buf, size_t buf_size) noexcept |
| Write ANSI reset sequence into a buffer. | |
| static std::unique_ptr< BaseLogger > | CreateDefaultBaseLogger () noexcept |
Resolve the platform-default BaseLogger. | |
Private Attributes | |
| std::atomic< bool > | initialized_ |
| LogConfig | config_ |
| TagLevel | tag_levels_ [kMaxTagLevels] = {} |
| std::unique_ptr< BaseLogger > | base_logger_ |
Static Private Attributes | |
| static constexpr size_t | kMaxTagLevels = 16 |
| Fixed-size tag-level storage (avoids std::map heap allocation) | |
| static constexpr size_t | kMaxTagLength = 32 |
Advanced logging system with formatting capabilities.
This class provides a comprehensive logging solution that supports various formatting options including colors, styles, and effects. It can also handle ASCII art formatting and display.
Key Features:
Usage Example:
|
privatenoexcept |
Constructor.
|
privatenoexcept |
Destructor.
|
privatedelete |
Copy constructor (deleted)
|
privatedelete |
Move constructor (deleted)
|
staticprivatenoexcept |
Resolve the platform-default BaseLogger.
Implemented in a per-MCU factory translation unit (logger/factory/EspLoggerFactory.cpp on ESP32). Defined as a free function so Logger.cpp itself never #includes EspLogger.h / esp_log.h — keeping the handler MCU-agnostic.
|
noexcept |
Log debug message.
| tag | Log tag |
| format | Format string |
| ... | Variable arguments |
|
noexcept |
Log debug message with formatting.
| tag | Log tag |
| color | Text color |
| style | Text style |
| format | Format string |
| ... | Variable arguments |
|
noexcept |
Deinitialize the logger.
|
privatenoexcept |
Dump comprehensive logger statistics to log as INFO level. Logs internal logger statistics, configuration, and performance metrics.
|
noexcept |
Enable/disable ASCII art support.
| enable | true to enable, false to disable |
|
noexcept |
Enable/disable colors.
| enable | true to enable, false to disable |
|
noexcept |
Enable/disable effects.
| enable | true to enable, false to disable |
|
noexcept |
Log error message.
| tag | Log tag |
| format | Format string |
| ... | Variable arguments |
|
noexcept |
Log error message with formatting.
| tag | Log tag |
| color | Text color |
| style | Text style |
| format | Format string |
| ... | Variable arguments |
|
noexcept |
Flush any buffered output.
|
privatenoexcept |
Format and log ASCII art line-by-line without heap allocation.
| tag | Log tag |
| level | Log level for output |
| ascii_art | ASCII art C string |
| format | Formatting options |
|
noexcept |
Get current configuration.
|
noexcept |
Get log level for a tag.
| tag | Log tag |
|
noexcept |
Log info message.
| tag | Log tag |
| format | Format string |
| ... | Variable arguments |
|
noexcept |
Log info message with formatting.
| tag | Log tag |
| color | Text color |
| style | Text style |
| format | Format string |
| ... | Variable arguments |
|
noexcept |
Initialize the logger with a caller-supplied BaseLogger.
This is the layering-clean entry point: the HAL (or a unit test) picks the backend and hands it to the logger. Logger takes ownership; Initialize calls BaseLogger::Initialize(...) on it with the matching hf_logger_config_t.
| config | Configuration options. |
| backend | Concrete backend (e.g. std::make_unique<EspLogger>() from the HAL, or a test double). Must be non-null. |
backend is null or its Initialize reports failure. Initialize the logger using the platform-default BaseLogger backend (resolved via the MCU-specific logger factory).
On ESP32 the default factory hands back an EspLogger; on other platforms it returns whatever was linked into logger/factory/<mcu>LoggerFactory.cpp. If you need to drive the logger output through a different transport (e.g. the built-in USB Serial/JTAG controller via EspUsbSerialJtag), use the injection overload below instead — Logger.cpp itself is MCU-clean and never names a concrete BaseLogger subclass.
| config | Configuration options. |
|
noexcept |
Check if logger is initialized.
|
privatenoexcept |
Check if log level is enabled for tag.
| level | Log level |
| tag | Log tag |
|
noexcept |
Log ASCII art.
| tag | Log tag |
| ascii_art | ASCII art string |
| format | Formatting options |
|
noexcept |
Log ASCII art with log level.
| level | Log level |
| tag | Log tag |
| ascii_art | ASCII art string |
| format | Formatting options |
|
noexcept |
Log ASCII art banner.
| tag | Log tag |
| ascii_art | ASCII art string |
| format | Formatting options |
|
privatenoexcept |
Internal logging method.
| level | Log level |
| tag | Log tag |
| color | Text color |
| style | Text style |
| format | Format string |
| args | Variable arguments |
|
noexcept |
Set default configuration.
| config | Configuration |
|
noexcept |
Set log level for a tag.
| tag | Log tag |
| level | Log level |
|
noexcept |
Set the minimum visible log level for messages emitted with a specific tag (e.g. throttle a noisy HAL handler during a boot self-test).
MCU-agnostic wrapper: on ESP32 this maps to esp_log_level_set; on platforms without per-tag filtering it is a no-op (messages still pass through, the global level governs).
| tag | Tag string passed to Info / Warn / Error etc. |
| level | Minimum severity that should still print for tag. |
|
noexcept |
Log verbose message.
| tag | Log tag |
| format | Format string |
| ... | Variable arguments |
|
noexcept |
Log verbose message with formatting.
| tag | Log tag |
| color | Text color |
| style | Text style |
| format | Format string |
| ... | Variable arguments |
|
noexcept |
Log warning message.
| tag | Log tag |
| format | Format string |
| ... | Variable arguments |
|
noexcept |
Log warning message with formatting.
| tag | Log tag |
| color | Text color |
| style | Text style |
| format | Format string |
| ... | Variable arguments |
|
privatenoexcept |
Write ANSI color/style prefix into a buffer.
| buf | Output buffer |
| buf_size | Buffer size |
| color | Text color |
| background | Background color |
| style | Text style |
|
staticprivatenoexcept |
Write ANSI reset sequence into a buffer.
| buf | Output buffer |
| buf_size | Buffer size |
|
private |
|
private |
|
private |
|
staticconstexprprivate |
|
staticconstexprprivate |
Fixed-size tag-level storage (avoids std::map heap allocation)
|
private |