attributes passed to root API

pull/2687/head
Bailey Chittle 3 years ago
parent 76b7158ec1
commit 7e2a93191a

@ -16,6 +16,13 @@ struct attr
std::string value;
public:
attr(std::initializer_list<std::string_view> 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"}

@ -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<typename... Args>
void log(source_loc loc, level::level_enum lvl, format_string_t<Args...> 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);

Loading…
Cancel
Save