idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches
idfxx::log::logger Class Reference

Lightweight logger bound to a specific tag. More...

Public Member Functions

constexpr logger (const char *tag) noexcept
 Construct a logger with the given tag.
 
constexpr const char * tag () const noexcept
 Get the tag associated with this logger.
 
template<typename... Args>
void log (level lvl, std::format_string< Args... > fmt, Args &&... args) const
 Log a message at the specified level.
 
void log (level lvl, std::string_view msg) const
 Log a pre-formatted message at the specified level.
 
template<typename... Args>
void error (std::format_string< Args... > fmt, Args &&... args) const
 Log a message at error level.
 
void error (std::string_view msg) const
 Log a pre-formatted message at error level.
 
template<typename... Args>
void warn (std::format_string< Args... > fmt, Args &&... args) const
 Log a message at warning level.
 
void warn (std::string_view msg) const
 Log a pre-formatted message at warning level.
 
template<typename... Args>
void info (std::format_string< Args... > fmt, Args &&... args) const
 Log a message at info level.
 
void info (std::string_view msg) const
 Log a pre-formatted message at info level.
 
template<typename... Args>
void debug (std::format_string< Args... > fmt, Args &&... args) const
 Log a message at debug level.
 
void debug (std::string_view msg) const
 Log a pre-formatted message at debug level.
 
template<typename... Args>
void verbose (std::format_string< Args... > fmt, Args &&... args) const
 Log a message at verbose level.
 
void verbose (std::string_view msg) const
 Log a pre-formatted message at verbose level.
 
void set_level (level lvl) const
 Set the runtime log level for this logger's tag.
 
void buffer_hex (level lvl, const void *buffer, size_t length) const
 Log a buffer as hexadecimal bytes.
 
void buffer_char (level lvl, const void *buffer, size_t length) const
 Log a buffer as printable characters.
 
void buffer_hex_dump (level lvl, const void *buffer, size_t length) const
 Log a buffer as a formatted hex dump.
 

Detailed Description

Lightweight logger bound to a specific tag.

A value type that associates a tag string with logging methods, avoiding repetition of the tag in every call. The tag pointer must remain valid for the lifetime of the logger (string literals are recommended).

static constexpr idfxx::log::logger log{"my_component"};
void do_work() {
log.info("Starting work with {} items", count);
// ...
log.error("Failed to process item {}: {}", id, reason);
}
Lightweight logger bound to a specific tag.
Definition log.hpp:304
void log(level lvl, std::format_string< Args... > fmt, Args &&... args) const
Log a message at the specified level.
Definition log.hpp:331

Definition at line 304 of file log.hpp.

Constructor & Destructor Documentation

◆ logger()

constexpr idfxx::log::logger::logger ( const char *  tag)
inlineexplicitconstexprnoexcept

Construct a logger with the given tag.

Parameters
tagThe log tag identifying the source. Must remain valid for the lifetime of the logger. String literals are recommended.

Definition at line 312 of file log.hpp.

Member Function Documentation

◆ buffer_char()

void idfxx::log::logger::buffer_char ( level  lvl,
const void *  buffer,
size_t  length 
) const
inline

Log a buffer as printable characters.

Parameters
lvlThe log severity level.
bufferPointer to the buffer data.
lengthNumber of bytes to log.

Definition at line 466 of file log.hpp.

References idfxx::log::buffer_char().

◆ buffer_hex()

void idfxx::log::logger::buffer_hex ( level  lvl,
const void *  buffer,
size_t  length 
) const
inline

Log a buffer as hexadecimal bytes.

Parameters
lvlThe log severity level.
bufferPointer to the buffer data.
lengthNumber of bytes to log.

Definition at line 455 of file log.hpp.

References idfxx::log::buffer_hex().

◆ buffer_hex_dump()

void idfxx::log::logger::buffer_hex_dump ( level  lvl,
const void *  buffer,
size_t  length 
) const
inline

Log a buffer as a formatted hex dump.

Parameters
lvlThe log severity level.
bufferPointer to the buffer data.
lengthNumber of bytes to log.

Definition at line 477 of file log.hpp.

References idfxx::log::buffer_hex_dump().

◆ debug() [1/2]

template<typename... Args>
void idfxx::log::logger::debug ( std::format_string< Args... >  fmt,
Args &&...  args 
) const
inline

Log a message at debug level.

Template Parameters
ArgsFormat argument types, deduced from the arguments.
Parameters
fmtA std::format format string, validated at compile time.
argsArguments to format into the message.

Definition at line 408 of file log.hpp.

References idfxx::log::debug.

◆ debug() [2/2]

void idfxx::log::logger::debug ( std::string_view  msg) const
inline

Log a pre-formatted message at debug level.

Parameters
msgThe message string to log.

Definition at line 417 of file log.hpp.

References idfxx::log::debug.

◆ error() [1/2]

template<typename... Args>
void idfxx::log::logger::error ( std::format_string< Args... >  fmt,
Args &&...  args 
) const
inline

Log a message at error level.

Template Parameters
ArgsFormat argument types, deduced from the arguments.
Parameters
fmtA std::format format string, validated at compile time.
argsArguments to format into the message.

Definition at line 351 of file log.hpp.

References idfxx::log::error.

◆ error() [2/2]

void idfxx::log::logger::error ( std::string_view  msg) const
inline

Log a pre-formatted message at error level.

Parameters
msgThe message string to log.

Definition at line 360 of file log.hpp.

References idfxx::log::error.

◆ info() [1/2]

template<typename... Args>
void idfxx::log::logger::info ( std::format_string< Args... >  fmt,
Args &&...  args 
) const
inline

Log a message at info level.

Template Parameters
ArgsFormat argument types, deduced from the arguments.
Parameters
fmtA std::format format string, validated at compile time.
argsArguments to format into the message.

Definition at line 389 of file log.hpp.

References idfxx::log::info.

◆ info() [2/2]

void idfxx::log::logger::info ( std::string_view  msg) const
inline

Log a pre-formatted message at info level.

Parameters
msgThe message string to log.

Definition at line 398 of file log.hpp.

References idfxx::log::info.

◆ log() [1/2]

template<typename... Args>
void idfxx::log::logger::log ( level  lvl,
std::format_string< Args... >  fmt,
Args &&...  args 
) const
inline

Log a message at the specified level.

Template Parameters
ArgsFormat argument types, deduced from the arguments.
Parameters
lvlThe log severity level.
fmtA std::format format string, validated at compile time.
argsArguments to format into the message.

Definition at line 331 of file log.hpp.

References idfxx::log::log().

◆ log() [2/2]

void idfxx::log::logger::log ( level  lvl,
std::string_view  msg 
) const
inline

Log a pre-formatted message at the specified level.

Parameters
lvlThe log severity level.
msgThe message string to log.

Definition at line 341 of file log.hpp.

References idfxx::log::log().

◆ set_level()

void idfxx::log::logger::set_level ( level  lvl) const

Set the runtime log level for this logger's tag.

Messages with a severity below the configured level are suppressed at runtime.

Parameters
lvlThe minimum severity level to output.

◆ tag()

constexpr const char * idfxx::log::logger::tag ( ) const
inlineconstexprnoexcept

Get the tag associated with this logger.

Returns
The log tag string.

Definition at line 320 of file log.hpp.

◆ verbose() [1/2]

template<typename... Args>
void idfxx::log::logger::verbose ( std::format_string< Args... >  fmt,
Args &&...  args 
) const
inline

Log a message at verbose level.

Template Parameters
ArgsFormat argument types, deduced from the arguments.
Parameters
fmtA std::format format string, validated at compile time.
argsArguments to format into the message.

Definition at line 427 of file log.hpp.

References idfxx::log::verbose.

◆ verbose() [2/2]

void idfxx::log::logger::verbose ( std::string_view  msg) const
inline

Log a pre-formatted message at verbose level.

Parameters
msgThe message string to log.

Definition at line 436 of file log.hpp.

References idfxx::log::verbose.

◆ warn() [1/2]

template<typename... Args>
void idfxx::log::logger::warn ( std::format_string< Args... >  fmt,
Args &&...  args 
) const
inline

Log a message at warning level.

Template Parameters
ArgsFormat argument types, deduced from the arguments.
Parameters
fmtA std::format format string, validated at compile time.
argsArguments to format into the message.

Definition at line 370 of file log.hpp.

References idfxx::log::warn.

◆ warn() [2/2]

void idfxx::log::logger::warn ( std::string_view  msg) const
inline

Log a pre-formatted message at warning level.

Parameters
msgThe message string to log.

Definition at line 379 of file log.hpp.

References idfxx::log::warn.


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