Commit 2848e517 authored by gabime's avatar gabime

Clean log_msg_buffer

parent 0db49788
...@@ -9,56 +9,26 @@ ...@@ -9,56 +9,26 @@
namespace spdlog { namespace spdlog {
namespace details { namespace details {
// regular log_msgs hold string_views to stack data - so they cannot be stored for later use. // extend log_msg with internal buffer to store its payload.
// this one can, since it contains and owns the payload buffer. // this is needed since log_msg holds string_views that points to stack data.
struct log_msg_buffer : log_msg struct log_msg_buffer : log_msg
{ {
fmt::basic_memory_buffer<char, 40> loggername_buf; fmt::basic_memory_buffer<char, 200> buffer;
fmt::basic_memory_buffer<char, 200> payload_buf;
log_msg_buffer() = default; log_msg_buffer() = default;
explicit log_msg_buffer(const log_msg &orig_msg) explicit log_msg_buffer(const log_msg &orig_msg)
: log_msg(orig_msg) : log_msg(orig_msg)
{ {
update_buffers(); buffer.append(logger_name.begin(), logger_name.end());
} logger_name = string_view_t{buffer.data(), buffer.size()};
log_msg_buffer(const log_msg_buffer &other)
: log_msg(other)
{
update_buffers();
}
log_msg_buffer(const log_msg_buffer &&other) SPDLOG_NOEXCEPT buffer.append(payload.begin(), payload.end());
: log_msg(std::move(other)) payload = string_view_t{logger_name.end(), payload.size()};
{
update_buffers();
} }
log_msg_buffer &operator=(const log_msg_buffer &other) SPDLOG_NOEXCEPT log_msg_buffer(log_msg_buffer &&other) = default;
{ log_msg_buffer &operator=(log_msg_buffer &&other) = default;
*static_cast<log_msg *>(this) = other;
update_buffers();
return *this;
}
log_msg_buffer &operator=(log_msg_buffer &&other) SPDLOG_NOEXCEPT
{
*static_cast<log_msg *>(this) = std::move(other);
update_buffers();
return *this;
}
void update_buffers() SPDLOG_NOEXCEPT
{
loggername_buf.clear();
loggername_buf.append(logger_name.data(), logger_name.data() + logger_name.size());
logger_name = string_view_t{loggername_buf.data(), loggername_buf.size()};
payload_buf.clear();
payload_buf.append(payload.data(), payload.data() + payload.size());
payload = string_view_t{payload_buf.data(), payload_buf.size()};
}
}; };
} // namespace details } // namespace details
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment