7#ifndef CONFIG_IDFXX_STD_FORMAT
8#error "idfxx_log requires CONFIG_IDFXX_STD_FORMAT to be enabled (menuconfig -> IDFXX -> Enable std::format support)"
54 error = ESP_LOG_ERROR,
57 debug = ESP_LOG_DEBUG,
72void log(
level lvl,
const char* tag, std::string_view msg);
87template<
typename... Args>
88void log(
level lvl,
const char* tag, std::format_string<Args...> fmt, Args&&... args) {
89 if (
static_cast<int>(lvl) > LOG_LOCAL_LEVEL) {
92 if (esp_log_level_get(tag) <
static_cast<esp_log_level_t
>(lvl)) {
95 log(lvl, tag, std::format(fmt, std::forward<Args>(args)...));
107template<
typename... Args>
108void error(
const char* tag, std::format_string<Args...> fmt, Args&&... args) {
119inline void error(
const char* tag, std::string_view msg) {
132template<
typename... Args>
133void warn(
const char* tag, std::format_string<Args...> fmt, Args&&... args) {
144inline void warn(
const char* tag, std::string_view msg) {
157template<
typename... Args>
158void info(
const char* tag, std::format_string<Args...> fmt, Args&&... args) {
169inline void info(
const char* tag, std::string_view msg) {
182template<
typename... Args>
183void debug(
const char* tag, std::format_string<Args...> fmt, Args&&... args) {
194inline void debug(
const char* tag, std::string_view msg) {
207template<
typename... Args>
208void verbose(
const char* tag, std::format_string<Args...> fmt, Args&&... args) {
219inline void verbose(
const char* tag, std::string_view msg) {
320 [[nodiscard]]
constexpr const char*
tag() const noexcept {
return _tag; }
330 template<
typename... Args>
331 void log(
level lvl, std::format_string<Args...> fmt, Args&&... args)
const {
350 template<
typename... Args>
351 void error(std::format_string<Args...> fmt, Args&&... args)
const {
369 template<
typename... Args>
370 void warn(std::format_string<Args...> fmt, Args&&... args)
const {
388 template<
typename... Args>
389 void info(std::format_string<Args...> fmt, Args&&... args)
const {
407 template<
typename... Args>
408 void debug(std::format_string<Args...> fmt, Args&&... args)
const {
426 template<
typename... Args>
427 void verbose(std::format_string<Args...> fmt, Args&&... args)
const {
511 return "unknown(" + std::to_string(
static_cast<unsigned int>(lvl)) +
")";
522struct formatter<
idfxx::log::level> {
523 constexpr auto parse(format_parse_context& ctx) {
return ctx.begin(); }
525 template<
typename FormatContext>
528 return std::copy(s.begin(), s.end(), ctx.out());
546#define IDFXX_LOGE(tag, fmt, ...) \
548 if (LOG_LOCAL_LEVEL >= ESP_LOG_ERROR) { \
549 idfxx::log::error(tag, fmt __VA_OPT__(, ) __VA_ARGS__); \
560#define IDFXX_LOGW(tag, fmt, ...) \
562 if (LOG_LOCAL_LEVEL >= ESP_LOG_WARN) { \
563 idfxx::log::warn(tag, fmt __VA_OPT__(, ) __VA_ARGS__); \
574#define IDFXX_LOGI(tag, fmt, ...) \
576 if (LOG_LOCAL_LEVEL >= ESP_LOG_INFO) { \
577 idfxx::log::info(tag, fmt __VA_OPT__(, ) __VA_ARGS__); \
588#define IDFXX_LOGD(tag, fmt, ...) \
590 if (LOG_LOCAL_LEVEL >= ESP_LOG_DEBUG) { \
591 idfxx::log::debug(tag, fmt __VA_OPT__(, ) __VA_ARGS__); \
602#define IDFXX_LOGV(tag, fmt, ...) \
604 if (LOG_LOCAL_LEVEL >= ESP_LOG_VERBOSE) { \
605 idfxx::log::verbose(tag, fmt __VA_OPT__(, ) __VA_ARGS__); \
Lightweight logger bound to a specific tag.
void error(std::string_view msg) const
Log a pre-formatted message at error level.
void buffer_char(level lvl, const void *buffer, size_t length) const
Log a buffer as printable characters.
void debug(std::string_view msg) const
Log a pre-formatted message at debug level.
void debug(std::format_string< Args... > fmt, Args &&... args) const
Log a message at debug level.
void info(std::string_view msg) const
Log a pre-formatted message at info level.
void log(level lvl, std::format_string< Args... > fmt, Args &&... args) const
Log a message at the specified level.
void buffer_hex(level lvl, const void *buffer, size_t length) const
Log a buffer as hexadecimal bytes.
void verbose(std::string_view msg) const
Log a pre-formatted message at verbose level.
void log(level lvl, std::string_view msg) const
Log a pre-formatted message at the specified level.
void warn(std::string_view msg) const
Log a pre-formatted message at warning level.
void error(std::format_string< Args... > fmt, Args &&... args) const
Log a message at error level.
void buffer_hex_dump(level lvl, const void *buffer, size_t length) const
Log a buffer as a formatted hex dump.
void warn(std::format_string< Args... > fmt, Args &&... args) const
Log a message at warning level.
void verbose(std::format_string< Args... > fmt, Args &&... args) const
Log a message at verbose level.
constexpr const char * tag() const noexcept
Get the tag associated with this logger.
constexpr logger(const char *tag) noexcept
Construct a logger with the given tag.
void info(std::format_string< Args... > fmt, Args &&... args) const
Log a message at info level.
void set_level(level lvl) const
Set the runtime log level for this logger's tag.
std::string to_string(core_id c)
Returns a string representation of a CPU core identifier.
void buffer_hex_dump(level lvl, const char *tag, const void *buffer, size_t length)
Log a buffer as a formatted hex dump.
void set_level(const char *tag, level lvl)
Set the runtime log level for a specific tag.
void log(level lvl, const char *tag, std::string_view msg)
Log a pre-formatted message at the specified level.
void set_default_level(level lvl)
Set the default log level for all tags.
void buffer_char(level lvl, const char *tag, const void *buffer, size_t length)
Log a buffer as printable characters.
@ warn
Warning conditions that may indicate problems.
@ verbose
Highly detailed trace information.
@ debug
Detailed information for debugging.
@ info
Informational messages about normal operation.
@ error
Critical errors requiring immediate attention.
void buffer_hex(level lvl, const char *tag, const void *buffer, size_t length)
Log a buffer as hexadecimal bytes.