Updated log_msg to accept attributes

This commit is contained in:
M4rFri 2024-07-05 12:57:01 +02:00 committed by M4rFri
parent d193833d4a
commit f24c55016c
2 changed files with 58 additions and 0 deletions

View File

@ -5,14 +5,23 @@
#include <string>
#include "../attributes.h"
#include "../common.h"
namespace spdlog {
namespace details {
struct SPDLOG_API log_msg {
log_msg() = default;
log_msg(log_clock::time_point log_time,
source_loc loc,
string_view_t logger_name,
level lvl,
string_view_t msg,
log_attributes attributes);
log_msg(log_clock::time_point log_time, const source_loc &loc, string_view_t logger_name, level lvl, string_view_t msg);
log_msg(const source_loc &loc, string_view_t logger_name, level lvl, string_view_t msg);
log_msg(source_loc loc, string_view_t logger_name, level lvl, string_view_t msg, log_attributes attributes);
log_msg(string_view_t logger_name, level lvl, string_view_t msg, log_attributes attributes);
log_msg(string_view_t logger_name, level lvl, string_view_t msg);
log_msg(const log_msg &other) = default;
log_msg &operator=(const log_msg &other) = default;
@ -28,6 +37,7 @@ struct SPDLOG_API log_msg {
source_loc source;
string_view_t payload;
log_attributes attributes;
};
} // namespace details
} // namespace spdlog

View File

@ -8,6 +8,44 @@
namespace spdlog {
namespace details {
log_msg::log_msg(spdlog::log_clock::time_point log_time,
spdlog::source_loc loc,
string_view_t a_logger_name,
spdlog::level lvl,
spdlog::string_view_t msg,
spdlog::log_attributes attributes)
: logger_name(a_logger_name),
log_level(lvl),
time(log_time)
#ifndef SPDLOG_NO_THREAD_ID
,
thread_id(os::thread_id())
#endif
,
source(loc),
payload(msg),
attributes(attributes) {
}
log_msg::log_msg(const log_clock::time_point log_time,
const source_loc loc,
const string_view_t a_logger_name,
const level lvl,
const string_view_t msg,
const log_attributes attributes)
: logger_name(a_logger_name),
log_level(lvl),
time(log_time),
#ifdef SPDLOG_NO_THREAD_ID
thread_id(0),
#else
thread_id(os::thread_id()),
#endif
source(loc),
payload(msg),
attributes(attributes) {
}
log_msg::log_msg(const log_clock::time_point log_time,
const source_loc &loc,
const string_view_t logger_name,
@ -28,8 +66,18 @@ log_msg::log_msg(const log_clock::time_point log_time,
log_msg::log_msg(const source_loc &loc, const string_view_t logger_name, const level lvl, const string_view_t msg)
: log_msg(os::now(), loc, logger_name, lvl, msg) {}
log_msg::log_msg(spdlog::source_loc loc,
string_view_t a_logger_name,
spdlog::level lvl,
spdlog::string_view_t msg,
spdlog::log_attributes attributes)
: log_msg(os::now(), loc, a_logger_name, lvl, msg, attributes) {}
log_msg::log_msg(const string_view_t logger_name, const level lvl, const string_view_t msg)
: log_msg(os::now(), source_loc{}, logger_name, lvl, msg) {}
log_msg::log_msg(string_view_t a_logger_name, spdlog::level lvl, spdlog::string_view_t msg, spdlog::log_attributes attributes)
: log_msg(os::now(), source_loc{}, a_logger_name, lvl, msg, attributes) {}
} // namespace details
} // namespace spdlog