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 chartag () 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, uint16_t length) const
 Log a buffer as hexadecimal bytes.
 
template<std::ranges::contiguous_range R>
requires (sizeof(std::ranges::range_value_t<R>) == 1)
void buffer_hex (level lvl, const R &data) const
 Log a contiguous range as hexadecimal bytes.
 
void buffer_char (level lvl, const void *buffer, uint16_t length) const
 Log a buffer as printable characters.
 
template<std::ranges::contiguous_range R>
requires (sizeof(std::ranges::range_value_t<R>) == 1)
void buffer_char (level lvl, const R &data) const
 Log a contiguous range as printable characters.
 
void buffer_hex_dump (level lvl, const void *buffer, uint16_t length) const
 Log a buffer as a formatted hex dump.
 
template<std::ranges::contiguous_range R>
requires (sizeof(std::ranges::range_value_t<R>) == 1)
void buffer_hex_dump (level lvl, const R &data) const
 Log a contiguous range 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:364
void log(level lvl, std::format_string< Args... > fmt, Args &&... args) const
Log a message at the specified level.
Definition log.hpp:391
std::expected< T, std::error_code > result
result type wrapping a value or error code.
Definition error.hpp:120

Definition at line 364 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 372 of file log.hpp.

Member Function Documentation

◆ buffer_char() [1/2]

template<std::ranges::contiguous_range R>
requires (sizeof(std::ranges::range_value_t<R>) == 1)
void idfxx::log::logger::buffer_char ( level  lvl,
const R data 
) const
inline

Log a contiguous range as printable characters.

Non-printable characters are not shown. Only the first 65535 bytes are logged; any remainder is silently truncated.

Template Parameters
RA contiguous range type (e.g., std::vector, std::span, std::array).
Parameters
lvlThe log severity level.
dataThe data to log.

Definition at line 557 of file log.hpp.

References idfxx::log::buffer_char().

◆ buffer_char() [2/2]

void idfxx::log::logger::buffer_char ( level  lvl,
const void buffer,
uint16_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 541 of file log.hpp.

References idfxx::log::buffer_char().

◆ buffer_hex() [1/2]

template<std::ranges::contiguous_range R>
requires (sizeof(std::ranges::range_value_t<R>) == 1)
void idfxx::log::logger::buffer_hex ( level  lvl,
const R data 
) const
inline

Log a contiguous range as hexadecimal bytes.

Only the first 65535 bytes are logged; any remainder is silently truncated.

Template Parameters
RA contiguous range type (e.g., std::vector, std::span, std::array).
Parameters
lvlThe log severity level.
dataThe data to log.

Definition at line 530 of file log.hpp.

References idfxx::log::buffer_hex().

◆ buffer_hex() [2/2]

void idfxx::log::logger::buffer_hex ( level  lvl,
const void buffer,
uint16_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 515 of file log.hpp.

References idfxx::log::buffer_hex().

◆ buffer_hex_dump() [1/2]

template<std::ranges::contiguous_range R>
requires (sizeof(std::ranges::range_value_t<R>) == 1)
void idfxx::log::logger::buffer_hex_dump ( level  lvl,
const R data 
) const
inline

Log a contiguous range as a formatted hex dump.

Only the first 65535 bytes are logged; any remainder is silently truncated.

Template Parameters
RA contiguous range type (e.g., std::vector, std::span, std::array).
Parameters
lvlThe log severity level.
dataThe data to log.

Definition at line 583 of file log.hpp.

References idfxx::log::buffer_hex_dump().

◆ buffer_hex_dump() [2/2]

void idfxx::log::logger::buffer_hex_dump ( level  lvl,
const void buffer,
uint16_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 568 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 468 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 477 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 411 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 420 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 449 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 458 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 391 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 401 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 380 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 487 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 496 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 430 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 439 of file log.hpp.

References idfxx::log::warn.


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