mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-25 10:01:33 +08:00
Optimize logging for const char* messages
This commit is contained in:
parent
23db7a213d
commit
d3c1ad29a0
@ -22,12 +22,8 @@ inline void append_str(const std::string &str, fmt::basic_memory_buffer<char, Bu
|
|||||||
template<size_t Buffer_Size>
|
template<size_t Buffer_Size>
|
||||||
inline void append_c_str(const char *c_str, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
inline void append_c_str(const char *c_str, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
||||||
{
|
{
|
||||||
char ch;
|
auto len = std::char_traits<char>::length(c_str);
|
||||||
while ((ch = *c_str) != '\0')
|
dest.append(c_str, c_str + len);
|
||||||
{
|
|
||||||
dest.push_back(ch);
|
|
||||||
++c_str;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<size_t Buffer_Size1, size_t Buffer_Size2>
|
template<size_t Buffer_Size1, size_t Buffer_Size2>
|
||||||
|
@ -5,9 +5,12 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "spdlog/details/fmt_helper.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
// create logger with given name, sinks and the default pattern formatter
|
// create logger with given name, sinks and the default pattern formatter
|
||||||
// all other ctors will call this one
|
// all other ctors will call this one
|
||||||
template<typename It>
|
template<typename It>
|
||||||
@ -77,7 +80,7 @@ inline void spdlog::logger::log(level::level_enum lvl, const char *msg)
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
details::log_msg log_msg(&name_, lvl);
|
details::log_msg log_msg(&name_, lvl);
|
||||||
fmt::format_to(log_msg.raw, "{}", msg);
|
details::fmt_helper::append_c_str(msg, log_msg.raw);
|
||||||
sink_it_(log_msg);
|
sink_it_(log_msg);
|
||||||
}
|
}
|
||||||
SPDLOG_CATCH_AND_HANDLE
|
SPDLOG_CATCH_AND_HANDLE
|
||||||
|
Loading…
Reference in New Issue
Block a user