7#ifndef CONFIG_IDFXX_STD_FORMAT
8#error "idfxx_log requires CONFIG_IDFXX_STD_FORMAT to be enabled (menuconfig -> IDFXX -> Enable std::format support)"
55 error = ESP_LOG_ERROR,
58 debug = ESP_LOG_DEBUG,
73void log(
level lvl,
const char* tag, std::string_view msg);
88template<
typename... Args>
89void log(
level lvl,
const char* tag, std::format_string<Args...> fmt, Args&&... args) {
90 if (
static_cast<int>(lvl) > LOG_LOCAL_LEVEL) {
93 if (esp_log_level_get(tag) <
static_cast<esp_log_level_t
>(lvl)) {
96 log(lvl, tag, std::format(fmt, std::forward<Args>(args)...));
108template<
typename... Args>
109void error(
const char* tag, std::format_string<Args...> fmt, Args&&... args) {
120inline void error(
const char* tag, std::string_view msg) {
133template<
typename... Args>
134void warn(
const char* tag, std::format_string<Args...> fmt, Args&&... args) {
145inline void warn(
const char* tag, std::string_view msg) {
158template<
typename... Args>
159void info(
const char* tag, std::format_string<Args...> fmt, Args&&... args) {
170inline void info(
const char* tag, std::string_view msg) {
183template<
typename... Args>
184void debug(
const char* tag, std::format_string<Args...> fmt, Args&&... args) {
195inline void debug(
const char* tag, std::string_view msg) {
208template<
typename... Args>
209void verbose(
const char* tag, std::format_string<Args...> fmt, Args&&... args) {
220inline void verbose(
const char* tag, std::string_view msg) {
271template<std::ranges::contiguous_range R>
272 requires(
sizeof(std::ranges::range_value_t<R>) == 1)
274 auto sp = std::span(data);
275 buffer_hex(lvl, tag, sp.data(),
static_cast<uint16_t
>(std::min(sp.size(),
static_cast<size_t>(UINT16_MAX))));
305template<std::ranges::contiguous_range R>
306 requires(
sizeof(std::ranges::range_value_t<R>) == 1)
308 auto sp = std::span(data);
309 buffer_char(lvl, tag, sp.data(),
static_cast<uint16_t
>(std::min(sp.size(),
static_cast<size_t>(UINT16_MAX))));
339template<std::ranges::contiguous_range R>
340 requires(
sizeof(std::ranges::range_value_t<R>) == 1)
342 auto sp = std::span(data);
343 buffer_hex_dump(lvl, tag, sp.data(),
static_cast<uint16_t
>(std::min(sp.size(),
static_cast<size_t>(UINT16_MAX))));
380 [[nodiscard]]
constexpr const char*
tag() const noexcept {
return _tag; }
390 template<
typename... Args>
391 void log(
level lvl, std::format_string<Args...> fmt, Args&&... args)
const {
410 template<
typename... Args>
411 void error(std::format_string<Args...> fmt, Args&&... args)
const {
429 template<
typename... Args>
430 void warn(std::format_string<Args...> fmt, Args&&... args)
const {
448 template<
typename... Args>
449 void info(std::format_string<Args...> fmt, Args&&... args)
const {
467 template<
typename... Args>
468 void debug(std::format_string<Args...> fmt, Args&&... args)
const {
486 template<
typename... Args>
487 void verbose(std::format_string<Args...> fmt, Args&&... args)
const {
528 template<std::ranges::contiguous_range R>
529 requires(
sizeof(std::ranges::range_value_t<R>) == 1)
555 template<std::ranges::contiguous_range R>
556 requires(
sizeof(std::ranges::range_value_t<R>) == 1)
581 template<std::ranges::contiguous_range R>
582 requires(
sizeof(std::ranges::range_value_t<R>) == 1)
617 return "unknown(" + std::to_string(
static_cast<unsigned int>(lvl)) +
")";
628struct formatter<
idfxx::log::level> {
629 constexpr auto parse(format_parse_context& ctx) {
return ctx.begin(); }
631 template<
typename FormatContext>
634 return std::copy(s.begin(), s.end(), ctx.out());
652#define IDFXX_LOGE(tag, fmt, ...) \
654 if (LOG_LOCAL_LEVEL >= ESP_LOG_ERROR) { \
655 idfxx::log::error(tag, fmt __VA_OPT__(, ) __VA_ARGS__); \
666#define IDFXX_LOGW(tag, fmt, ...) \
668 if (LOG_LOCAL_LEVEL >= ESP_LOG_WARN) { \
669 idfxx::log::warn(tag, fmt __VA_OPT__(, ) __VA_ARGS__); \
680#define IDFXX_LOGI(tag, fmt, ...) \
682 if (LOG_LOCAL_LEVEL >= ESP_LOG_INFO) { \
683 idfxx::log::info(tag, fmt __VA_OPT__(, ) __VA_ARGS__); \
694#define IDFXX_LOGD(tag, fmt, ...) \
696 if (LOG_LOCAL_LEVEL >= ESP_LOG_DEBUG) { \
697 idfxx::log::debug(tag, fmt __VA_OPT__(, ) __VA_ARGS__); \
708#define IDFXX_LOGV(tag, fmt, ...) \
710 if (LOG_LOCAL_LEVEL >= ESP_LOG_VERBOSE) { \
711 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_hex(level lvl, const void *buffer, uint16_t length) const
Log a buffer as hexadecimal bytes.
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_dump(level lvl, const void *buffer, uint16_t length) const
Log a buffer as a formatted hex dump.
void verbose(std::string_view msg) const
Log a pre-formatted message at verbose level.
void buffer_hex(level lvl, const R &data) const
Log a contiguous range as hexadecimal bytes.
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 buffer_char(level lvl, const R &data) const
Log a contiguous range as printable characters.
void error(std::format_string< Args... > fmt, Args &&... args) const
Log a message at error level.
void buffer_char(level lvl, const void *buffer, uint16_t length) const
Log a buffer as printable characters.
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 buffer_hex_dump(level lvl, const R &data) const
Log a contiguous range as a formatted hex dump.
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 set_level(const char *tag, level lvl)
Set the runtime log level for a specific tag.
void buffer_hex(level lvl, const char *tag, const void *buffer, uint16_t length)
Log a buffer as hexadecimal bytes.
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, uint16_t length)
Log a buffer as printable characters.
void buffer_hex_dump(level lvl, const char *tag, const void *buffer, uint16_t length)
Log a buffer as a formatted hex dump.
@ 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.