diff --git a/include/spdlog/details/log_attr.h b/include/spdlog/details/log_attr.h index 0cf7ff34..5a177e27 100644 --- a/include/spdlog/details/log_attr.h +++ b/include/spdlog/details/log_attr.h @@ -16,6 +16,13 @@ struct attr std::string value; public: + attr(std::initializer_list l) { + if (l.size() != 2) return; // throw exception if not kv pair? + + key = *l.begin(); + value = *(l.begin()+1); + } + attr(std::string_view k, bool v) : key{k} , value{v ? "true" : "false"} diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index 1fafdabd..d2d44002 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -84,6 +84,11 @@ public: logger &operator=(logger other) SPDLOG_NOEXCEPT; void swap(spdlog::logger &other) SPDLOG_NOEXCEPT; + void log(level::level_enum lvl, const T &msg, details::attr attr) + { + log(source_loc{}, lvl, msg, attr); + } + template void log(source_loc loc, level::level_enum lvl, format_string_t fmt, Args &&... args) { @@ -122,6 +127,19 @@ public: log_it_(log_msg, log_enabled, traceback_enabled); } + void log(source_loc loc, level::level_enum lvl, string_view_t msg, details::attr attr) + { + bool log_enabled = should_log(lvl); + bool traceback_enabled = tracer_.enabled(); + if (!log_enabled && !traceback_enabled) + { + return; + } + + details::log_msg log_msg(loc, name_, lvl, msg); + log_msg.attributes.push_back(std::move(attr)); + log_it_(log_msg, log_enabled, traceback_enabled); + } void log(source_loc loc, level::level_enum lvl, string_view_t msg) { bool log_enabled = should_log(lvl);