Clean log_msg_buffer
This commit is contained in:
parent
0db4978899
commit
2848e51755
@ -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()};
|
||||||
|
|
||||||
|
buffer.append(payload.begin(), payload.end());
|
||||||
|
payload = string_view_t{logger_name.end(), payload.size()};
|
||||||
}
|
}
|
||||||
|
|
||||||
log_msg_buffer(const log_msg_buffer &other)
|
log_msg_buffer(log_msg_buffer &&other) = default;
|
||||||
: log_msg(other)
|
log_msg_buffer &operator=(log_msg_buffer &&other) = default;
|
||||||
{
|
|
||||||
update_buffers();
|
|
||||||
}
|
|
||||||
|
|
||||||
log_msg_buffer(const log_msg_buffer &&other) SPDLOG_NOEXCEPT
|
|
||||||
: log_msg(std::move(other))
|
|
||||||
{
|
|
||||||
update_buffers();
|
|
||||||
}
|
|
||||||
|
|
||||||
log_msg_buffer &operator=(const log_msg_buffer &other) SPDLOG_NOEXCEPT
|
|
||||||
{
|
|
||||||
*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
|
||||||
|
Loading…
Reference in New Issue
Block a user