HF-Core Platform 0.1.0-dev
Hardware-Agnostic Handler Layer & RTOS Utilities for HardFOC
Loading...
Searching...
No Matches
Logger Class Reference

Advanced logging system with formatting capabilities. More...

#include <Logger.h>

Collaboration diagram for Logger:
[legend]

Classes

struct  TagLevel
 

Public Member Functions

bool Initialize (const LogConfig &config=LogConfig{}) noexcept
 Initialize the logger.
 
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 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 LoggerGetInstance () noexcept
 Get singleton instance.
 

Private Member Functions

 Logger () noexcept
 Constructor.
 
 ~Logger () noexcept
 Destructor.
 
 Logger (const Logger &)=delete
 Copy constructor (deleted)
 
Loggeroperator= (const Logger &)=delete
 Assignment operator (deleted)
 
 Logger (Logger &&)=delete
 Move constructor (deleted)
 
Loggeroperator= (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.
 
std::unique_ptr< BaseLogger > CreateBaseLogger () noexcept
 Create base logger instance.
 
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.
 

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
 

Detailed Description

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:

  • Multiple Log Levels: Error, Warn, Info, Debug, Verbose
  • Color Support: ANSI color codes for text and background
  • Text Styling: Bold, italic, underline, strikethrough
  • ASCII Art Support: Format and display ASCII art
  • Effects: Borders, centering, padding
  • Performance Optimized: Efficient string handling
  • Thread Safe: Safe for multi-threaded environments

Usage Example:

// Basic logging
logger.Info("TAG", "Hello World");
// With formatting
logger.Info("TAG", "Hello World", LogColor::RED, LogStyle::BOLD);
// ASCII art
const char* ascii_art = "..."; // ASCII art string
logger.LogAsciiArt("BANNER", ascii_art, AsciiArtFormat{});
@ RED
Red.
@ BOLD
Bold text.
Advanced logging system with formatting capabilities.
Definition Logger.h:158
void Info(const char *tag, const char *format,...) noexcept
Log info message.
Definition Logger.cpp:192
static Logger & GetInstance() noexcept
Get singleton instance.
Definition Logger.cpp:61
void LogAsciiArt(const char *tag, const char *ascii_art, const AsciiArtFormat &format=AsciiArtFormat{}) noexcept
Log ASCII art.
Definition Logger.cpp:288
ASCII art formatting options.
Definition Logger.h:115

Constructor & Destructor Documentation

◆ Logger() [1/3]

Logger::Logger ( )
privatenoexcept

Constructor.

◆ ~Logger()

Logger::~Logger ( )
privatenoexcept

Destructor.

Here is the call graph for this function:

◆ Logger() [2/3]

Logger::Logger ( const Logger & )
privatedelete

Copy constructor (deleted)

◆ Logger() [3/3]

Logger::Logger ( Logger && )
privatedelete

Move constructor (deleted)

Member Function Documentation

◆ CreateBaseLogger()

std::unique_ptr< BaseLogger > Logger::CreateBaseLogger ( )
privatenoexcept

Create base logger instance.

Returns
Base logger instance

◆ Debug() [1/2]

void Logger::Debug ( const char * tag,
const char * format,
... )
noexcept

Log debug message.

Parameters
tagLog tag
formatFormat string
...Variable arguments
Here is the call graph for this function:

◆ Debug() [2/2]

void Logger::Debug ( const char * tag,
LogColor color,
LogStyle style,
const char * format,
... )
noexcept

Log debug message with formatting.

Parameters
tagLog tag
colorText color
styleText style
formatFormat string
...Variable arguments
Here is the call graph for this function:

◆ Deinitialize()

void Logger::Deinitialize ( )
noexcept

Deinitialize the logger.

Here is the caller graph for this function:

◆ DumpStatistics()

void Logger::DumpStatistics ( ) const
privatenoexcept

Dump comprehensive logger statistics to log as INFO level. Logs internal logger statistics, configuration, and performance metrics.

◆ EnableAsciiArt()

void Logger::EnableAsciiArt ( bool enable)
noexcept

Enable/disable ASCII art support.

Parameters
enabletrue to enable, false to disable

◆ EnableColors()

void Logger::EnableColors ( bool enable)
noexcept

Enable/disable colors.

Parameters
enabletrue to enable, false to disable

◆ EnableEffects()

void Logger::EnableEffects ( bool enable)
noexcept

Enable/disable effects.

Parameters
enabletrue to enable, false to disable

◆ Error() [1/2]

void Logger::Error ( const char * tag,
const char * format,
... )
noexcept

Log error message.

Parameters
tagLog tag
formatFormat string
...Variable arguments
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Error() [2/2]

void Logger::Error ( const char * tag,
LogColor color,
LogStyle style,
const char * format,
... )
noexcept

Log error message with formatting.

Parameters
tagLog tag
colorText color
styleText style
formatFormat string
...Variable arguments
Here is the call graph for this function:

◆ Flush()

void Logger::Flush ( )
noexcept

Flush any buffered output.

◆ FormatAndLogAsciiArt()

void Logger::FormatAndLogAsciiArt ( const char * tag,
LogLevel level,
const char * ascii_art,
const AsciiArtFormat & format )
privatenoexcept

Format and log ASCII art line-by-line without heap allocation.

Parameters
tagLog tag
levelLog level for output
ascii_artASCII art C string
formatFormatting options

◆ GetConfig()

LogConfig Logger::GetConfig ( ) const
noexcept

Get current configuration.

Returns
Current configuration

◆ GetInstance()

Logger & Logger::GetInstance ( )
staticnoexcept

Get singleton instance.

Returns
Logger instance

◆ GetLogLevel()

LogLevel Logger::GetLogLevel ( const char * tag) const
noexcept

Get log level for a tag.

Parameters
tagLog tag
Returns
Log level

◆ Info() [1/2]

void Logger::Info ( const char * tag,
const char * format,
... )
noexcept

Log info message.

Parameters
tagLog tag
formatFormat string
...Variable arguments
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Info() [2/2]

void Logger::Info ( const char * tag,
LogColor color,
LogStyle style,
const char * format,
... )
noexcept

Log info message with formatting.

Parameters
tagLog tag
colorText color
styleText style
formatFormat string
...Variable arguments
Here is the call graph for this function:

◆ Initialize()

bool Logger::Initialize ( const LogConfig & config = LogConfig{})
noexcept

Initialize the logger.

Parameters
configConfiguration options
Returns
true if successful, false otherwise
Here is the caller graph for this function:

◆ IsInitialized()

bool Logger::IsInitialized ( ) const
noexcept

Check if logger is initialized.

Returns
true if initialized, false otherwise

◆ IsLevelEnabled()

bool Logger::IsLevelEnabled ( LogLevel level,
const char * tag ) const
privatenoexcept

Check if log level is enabled for tag.

Parameters
levelLog level
tagLog tag
Returns
true if enabled, false otherwise
Here is the caller graph for this function:

◆ LogAsciiArt() [1/2]

void Logger::LogAsciiArt ( const char * tag,
const char * ascii_art,
const AsciiArtFormat & format = AsciiArtFormat{} )
noexcept

Log ASCII art.

Parameters
tagLog tag
ascii_artASCII art string
formatFormatting options

◆ LogAsciiArt() [2/2]

void Logger::LogAsciiArt ( LogLevel level,
const char * tag,
const char * ascii_art,
const AsciiArtFormat & format = AsciiArtFormat{} )
noexcept

Log ASCII art with log level.

Parameters
levelLog level
tagLog tag
ascii_artASCII art string
formatFormatting options

◆ LogBanner()

void Logger::LogBanner ( const char * tag,
const char * ascii_art,
const AsciiArtFormat & format = AsciiArtFormat{} )
noexcept

Log ASCII art banner.

Parameters
tagLog tag
ascii_artASCII art string
formatFormatting options

◆ LogInternal()

void Logger::LogInternal ( LogLevel level,
const char * tag,
LogColor color,
LogStyle style,
const char * format,
va_list args )
privatenoexcept

Internal logging method.

Parameters
levelLog level
tagLog tag
colorText color
styleText style
formatFormat string
argsVariable arguments
Here is the caller graph for this function:

◆ operator=() [1/2]

Logger & Logger::operator= ( const Logger & )
privatedelete

Assignment operator (deleted)

◆ operator=() [2/2]

Logger & Logger::operator= ( Logger && )
privatedelete

Move assignment operator (deleted)

◆ SetConfig()

void Logger::SetConfig ( const LogConfig & config)
noexcept

Set default configuration.

Parameters
configConfiguration

◆ SetLogLevel()

void Logger::SetLogLevel ( const char * tag,
LogLevel level )
noexcept

Set log level for a tag.

Parameters
tagLog tag
levelLog level

◆ Verbose() [1/2]

void Logger::Verbose ( const char * tag,
const char * format,
... )
noexcept

Log verbose message.

Parameters
tagLog tag
formatFormat string
...Variable arguments
Here is the call graph for this function:

◆ Verbose() [2/2]

void Logger::Verbose ( const char * tag,
LogColor color,
LogStyle style,
const char * format,
... )
noexcept

Log verbose message with formatting.

Parameters
tagLog tag
colorText color
styleText style
formatFormat string
...Variable arguments
Here is the call graph for this function:

◆ Warn() [1/2]

void Logger::Warn ( const char * tag,
const char * format,
... )
noexcept

Log warning message.

Parameters
tagLog tag
formatFormat string
...Variable arguments
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Warn() [2/2]

void Logger::Warn ( const char * tag,
LogColor color,
LogStyle style,
const char * format,
... )
noexcept

Log warning message with formatting.

Parameters
tagLog tag
colorText color
styleText style
formatFormat string
...Variable arguments
Here is the call graph for this function:

◆ WriteColorPrefix()

size_t Logger::WriteColorPrefix ( char * buf,
size_t buf_size,
LogColor color,
LogBackground background,
LogStyle style ) const
privatenoexcept

Write ANSI color/style prefix into a buffer.

Parameters
bufOutput buffer
buf_sizeBuffer size
colorText color
backgroundBackground color
styleText style
Returns
Number of bytes written (excluding null terminator)

◆ WriteResetSequence()

size_t Logger::WriteResetSequence ( char * buf,
size_t buf_size )
staticprivatenoexcept

Write ANSI reset sequence into a buffer.

Parameters
bufOutput buffer
buf_sizeBuffer size
Returns
Number of bytes written (excluding null terminator)

Member Data Documentation

◆ base_logger_

std::unique_ptr<BaseLogger> Logger::base_logger_
private

◆ config_

LogConfig Logger::config_
private

◆ initialized_

std::atomic<bool> Logger::initialized_
private

◆ kMaxTagLength

constexpr size_t Logger::kMaxTagLength = 32
staticconstexprprivate

◆ kMaxTagLevels

constexpr size_t Logger::kMaxTagLevels = 16
staticconstexprprivate

Fixed-size tag-level storage (avoids std::map heap allocation)

◆ tag_levels_

TagLevel Logger::tag_levels_[kMaxTagLevels] = {}
private

The documentation for this class was generated from the following files: