Use fmt::string_view when logging a C string to avoid unnecessary copy

This commit is contained in:
Jerome Meyer
2018-10-17 10:40:41 -04:00
parent 4b66e94ecf
commit cb71fea0f6
10 changed files with 93 additions and 9 deletions

View File

@@ -47,7 +47,7 @@ protected:
fmt::memory_buffer formatted;
if (use_raw_msg_)
{
details::fmt_helper::append_buf(msg.raw, formatted);
details::fmt_helper::append_msg(msg, formatted);
}
else
{

View File

@@ -53,7 +53,12 @@ public:
protected:
void sink_it_(const details::log_msg &msg) override
{
::syslog(syslog_prio_from_level(msg), "%s", fmt::to_string(msg.raw).c_str());
if (msg.c_string.data() != nullptr)
{
::syslog(syslog_prio_from_level(msg), "%.*s", static_cast<int>(msg.c_string.size()), msg.c_string.data());
} else {
::syslog(syslog_prio_from_level(msg), "%s", fmt::to_string(msg.raw).c_str());
}
}
void flush_() override {}