idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches
log.hpp File Reference

Type-safe logging with std::format. More...

#include "sdkconfig.h"
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <esp_log.h>
#include <format>
#include <string>
#include <string_view>
#include <utility>

Go to the source code of this file.

Classes

class  idfxx::log::logger
 Lightweight logger bound to a specific tag. More...
 

Namespaces

namespace  idfxx
 
namespace  idfxx::log
 

Macros

#define IDFXX_LOGE(tag, fmt, ...)
 Log at error level with zero-cost elimination when compile-time filtered.
 
#define IDFXX_LOGW(tag, fmt, ...)
 Log at warning level with zero-cost elimination when compile-time filtered.
 
#define IDFXX_LOGI(tag, fmt, ...)
 Log at info level with zero-cost elimination when compile-time filtered.
 
#define IDFXX_LOGD(tag, fmt, ...)
 Log at debug level with zero-cost elimination when compile-time filtered.
 
#define IDFXX_LOGV(tag, fmt, ...)
 Log at verbose level with zero-cost elimination when compile-time filtered.
 

Enumerations

enum class  idfxx::log::level : uint8_t {
  idfxx::log::none = ESP_LOG_NONE ,
  idfxx::log::error = ESP_LOG_ERROR ,
  idfxx::log::warn = ESP_LOG_WARN ,
  idfxx::log::info = ESP_LOG_INFO ,
  idfxx::log::debug = ESP_LOG_DEBUG ,
  idfxx::log::verbose = ESP_LOG_VERBOSE
}
 Log severity level. More...
 

Functions

void idfxx::log::log (level lvl, const char *tag, std::string_view msg)
 Log a pre-formatted message at the specified level.
 
template<typename... Args>
void idfxx::log::log (level lvl, const char *tag, std::format_string< Args... > fmt, Args &&... args)
 Log a message at the specified level.
 
template<typename... Args>
void idfxx::log::error (const char *tag, std::format_string< Args... > fmt, Args &&... args)
 Log a message at error level.
 
void idfxx::log::error (const char *tag, std::string_view msg)
 Log a pre-formatted message at error level.
 
template<typename... Args>
void idfxx::log::warn (const char *tag, std::format_string< Args... > fmt, Args &&... args)
 Log a message at warning level.
 
void idfxx::log::warn (const char *tag, std::string_view msg)
 Log a pre-formatted message at warning level.
 
template<typename... Args>
void idfxx::log::info (const char *tag, std::format_string< Args... > fmt, Args &&... args)
 Log a message at info level.
 
void idfxx::log::info (const char *tag, std::string_view msg)
 Log a pre-formatted message at info level.
 
template<typename... Args>
void idfxx::log::debug (const char *tag, std::format_string< Args... > fmt, Args &&... args)
 Log a message at debug level.
 
void idfxx::log::debug (const char *tag, std::string_view msg)
 Log a pre-formatted message at debug level.
 
template<typename... Args>
void idfxx::log::verbose (const char *tag, std::format_string< Args... > fmt, Args &&... args)
 Log a message at verbose level.
 
void idfxx::log::verbose (const char *tag, std::string_view msg)
 Log a pre-formatted message at verbose level.
 
void idfxx::log::set_level (const char *tag, level lvl)
 Set the runtime log level for a specific tag.
 
void idfxx::log::set_default_level (level lvl)
 Set the default log level for all tags.
 
void idfxx::log::buffer_hex (level lvl, const char *tag, const void *buffer, size_t length)
 Log a buffer as hexadecimal bytes.
 
void idfxx::log::buffer_char (level lvl, const char *tag, const void *buffer, size_t length)
 Log a buffer as printable characters.
 
void idfxx::log::buffer_hex_dump (level lvl, const char *tag, const void *buffer, size_t length)
 Log a buffer as a formatted hex dump.
 

Detailed Description

Type-safe logging with std::format.

Definition in file log.hpp.

Macro Definition Documentation

◆ IDFXX_LOGD

#define IDFXX_LOGD (   tag,
  fmt,
  ... 
)
Value:
do { \
if (LOG_LOCAL_LEVEL >= ESP_LOG_DEBUG) { \
idfxx::log::debug(tag, fmt __VA_OPT__(, ) __VA_ARGS__); \
} \
} while (0)

Log at debug level with zero-cost elimination when compile-time filtered.

Parameters
tagThe log tag (a const char*).
fmtA std::format format string.
...Arguments to format into the message.

Definition at line 588 of file log.hpp.

◆ IDFXX_LOGE

#define IDFXX_LOGE (   tag,
  fmt,
  ... 
)
Value:
do { \
if (LOG_LOCAL_LEVEL >= ESP_LOG_ERROR) { \
idfxx::log::error(tag, fmt __VA_OPT__(, ) __VA_ARGS__); \
} \
} while (0)

Log at error level with zero-cost elimination when compile-time filtered.

When LOG_LOCAL_LEVEL is set below ESP_LOG_ERROR, the compiler eliminates the entire log call including argument evaluation.

Parameters
tagThe log tag (a const char*).
fmtA std::format format string.
...Arguments to format into the message.

Definition at line 546 of file log.hpp.

◆ IDFXX_LOGI

#define IDFXX_LOGI (   tag,
  fmt,
  ... 
)
Value:
do { \
if (LOG_LOCAL_LEVEL >= ESP_LOG_INFO) { \
idfxx::log::info(tag, fmt __VA_OPT__(, ) __VA_ARGS__); \
} \
} while (0)

Log at info level with zero-cost elimination when compile-time filtered.

Parameters
tagThe log tag (a const char*).
fmtA std::format format string.
...Arguments to format into the message.

Definition at line 574 of file log.hpp.

◆ IDFXX_LOGV

#define IDFXX_LOGV (   tag,
  fmt,
  ... 
)
Value:
do { \
if (LOG_LOCAL_LEVEL >= ESP_LOG_VERBOSE) { \
idfxx::log::verbose(tag, fmt __VA_OPT__(, ) __VA_ARGS__); \
} \
} while (0)

Log at verbose level with zero-cost elimination when compile-time filtered.

Parameters
tagThe log tag (a const char*).
fmtA std::format format string.
...Arguments to format into the message.

Definition at line 602 of file log.hpp.

◆ IDFXX_LOGW

#define IDFXX_LOGW (   tag,
  fmt,
  ... 
)
Value:
do { \
if (LOG_LOCAL_LEVEL >= ESP_LOG_WARN) { \
idfxx::log::warn(tag, fmt __VA_OPT__(, ) __VA_ARGS__); \
} \
} while (0)

Log at warning level with zero-cost elimination when compile-time filtered.

Parameters
tagThe log tag (a const char*).
fmtA std::format format string.
...Arguments to format into the message.

Definition at line 560 of file log.hpp.