mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-28 09:09:35 +08:00
Unified usage of fmt::memory_buffer across the codebase
This commit is contained in:
@@ -10,7 +10,7 @@ static const std::string target_filename = "logs/file_helper_test.txt";
|
||||
|
||||
static void write_with_helper(file_helper &helper, size_t howmany)
|
||||
{
|
||||
fmt::memory_buffer formatted;
|
||||
spdlog::memory_buf_t formatted;
|
||||
fmt::format_to(formatted, "{}", std::string(howmany, '1'));
|
||||
helper.write(formatted);
|
||||
helper.flush();
|
||||
|
@@ -2,30 +2,32 @@
|
||||
#include "includes.h"
|
||||
#include "spdlog/details/fmt_helper.h"
|
||||
|
||||
using spdlog::memory_buf_t;
|
||||
|
||||
void test_pad2(int n, const char *expected)
|
||||
{
|
||||
fmt::memory_buffer buf;
|
||||
memory_buf_t buf;
|
||||
spdlog::details::fmt_helper::pad2(n, buf);
|
||||
REQUIRE(fmt::to_string(buf) == expected);
|
||||
}
|
||||
|
||||
void test_pad3(uint32_t n, const char *expected)
|
||||
{
|
||||
fmt::memory_buffer buf;
|
||||
memory_buf_t buf;
|
||||
spdlog::details::fmt_helper::pad3(n, buf);
|
||||
REQUIRE(fmt::to_string(buf) == expected);
|
||||
}
|
||||
|
||||
void test_pad6(std::size_t n, const char *expected)
|
||||
{
|
||||
fmt::memory_buffer buf;
|
||||
memory_buf_t buf;
|
||||
spdlog::details::fmt_helper::pad6(n, buf);
|
||||
REQUIRE(fmt::to_string(buf) == expected);
|
||||
}
|
||||
|
||||
void test_pad9(std::size_t n, const char *expected)
|
||||
{
|
||||
fmt::memory_buffer buf;
|
||||
memory_buf_t buf;
|
||||
spdlog::details::fmt_helper::pad9(n, buf);
|
||||
REQUIRE(fmt::to_string(buf) == expected);
|
||||
}
|
||||
|
@@ -1,8 +1,9 @@
|
||||
#include "includes.h"
|
||||
|
||||
using spdlog::memory_buf_t;
|
||||
|
||||
// log to str and return it
|
||||
template<typename... Args>
|
||||
|
||||
static std::string log_to_str(const std::string &msg, const Args &... args)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
@@ -61,9 +62,9 @@ TEST_CASE("color range test1", "[pattern_formatter]")
|
||||
{
|
||||
auto formatter = std::make_shared<spdlog::pattern_formatter>("%^%v%$", spdlog::pattern_time_type::local, "\n");
|
||||
|
||||
fmt::memory_buffer buf;
|
||||
memory_buf_t buf;
|
||||
fmt::format_to(buf, "Hello");
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
std::string logger_name = "test";
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, spdlog::string_view_t(buf.data(), buf.size()));
|
||||
formatter->format(msg, formatted);
|
||||
@@ -77,7 +78,7 @@ TEST_CASE("color range test2", "[pattern_formatter]")
|
||||
auto formatter = std::make_shared<spdlog::pattern_formatter>("%^%$", spdlog::pattern_time_type::local, "\n");
|
||||
std::string logger_name = "test";
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "");
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
formatter->format(msg, formatted);
|
||||
REQUIRE(msg.color_range_start == 0);
|
||||
REQUIRE(msg.color_range_end == 0);
|
||||
@@ -89,7 +90,7 @@ TEST_CASE("color range test3", "[pattern_formatter]")
|
||||
auto formatter = std::make_shared<spdlog::pattern_formatter>("%^***%$");
|
||||
std::string logger_name = "test";
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "ignored");
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
formatter->format(msg, formatted);
|
||||
REQUIRE(msg.color_range_start == 0);
|
||||
REQUIRE(msg.color_range_end == 3);
|
||||
@@ -101,7 +102,7 @@ TEST_CASE("color range test4", "[pattern_formatter]")
|
||||
std::string logger_name = "test";
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "ignored");
|
||||
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
formatter->format(msg, formatted);
|
||||
REQUIRE(msg.color_range_start == 2);
|
||||
REQUIRE(msg.color_range_end == 5);
|
||||
@@ -113,7 +114,7 @@ TEST_CASE("color range test5", "[pattern_formatter]")
|
||||
auto formatter = std::make_shared<spdlog::pattern_formatter>("**%^");
|
||||
std::string logger_name = "test";
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "ignored");
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
formatter->format(msg, formatted);
|
||||
REQUIRE(msg.color_range_start == 2);
|
||||
REQUIRE(msg.color_range_end == 0);
|
||||
@@ -124,7 +125,7 @@ TEST_CASE("color range test6", "[pattern_formatter]")
|
||||
auto formatter = std::make_shared<spdlog::pattern_formatter>("**%$");
|
||||
std::string logger_name = "test";
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "ignored");
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
formatter->format(msg, formatted);
|
||||
REQUIRE(msg.color_range_start == 0);
|
||||
REQUIRE(msg.color_range_end == 2);
|
||||
@@ -198,8 +199,8 @@ TEST_CASE("clone-default-formatter", "[pattern_formatter]")
|
||||
std::string logger_name = "test";
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "some message");
|
||||
|
||||
fmt::memory_buffer formatted_1;
|
||||
fmt::memory_buffer formatted_2;
|
||||
memory_buf_t formatted_1;
|
||||
memory_buf_t formatted_2;
|
||||
formatter_1->format(msg, formatted_1);
|
||||
formatter_2->format(msg, formatted_2);
|
||||
|
||||
@@ -213,8 +214,8 @@ TEST_CASE("clone-default-formatter2", "[pattern_formatter]")
|
||||
std::string logger_name = "test";
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "some message");
|
||||
|
||||
fmt::memory_buffer formatted_1;
|
||||
fmt::memory_buffer formatted_2;
|
||||
memory_buf_t formatted_1;
|
||||
memory_buf_t formatted_2;
|
||||
formatter_1->format(msg, formatted_1);
|
||||
formatter_2->format(msg, formatted_2);
|
||||
|
||||
@@ -228,8 +229,8 @@ TEST_CASE("clone-formatter", "[pattern_formatter]")
|
||||
std::string logger_name = "test";
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "some message");
|
||||
|
||||
fmt::memory_buffer formatted_1;
|
||||
fmt::memory_buffer formatted_2;
|
||||
memory_buf_t formatted_1;
|
||||
memory_buf_t formatted_2;
|
||||
formatter_1->format(msg, formatted_1);
|
||||
formatter_2->format(msg, formatted_2);
|
||||
REQUIRE(fmt::to_string(formatted_1) == fmt::to_string(formatted_2));
|
||||
@@ -243,8 +244,8 @@ TEST_CASE("clone-formatter-2", "[pattern_formatter]")
|
||||
std::string logger_name = "test2";
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "some message");
|
||||
|
||||
fmt::memory_buffer formatted_1;
|
||||
fmt::memory_buffer formatted_2;
|
||||
memory_buf_t formatted_1;
|
||||
memory_buf_t formatted_2;
|
||||
formatter_1->format(msg, formatted_1);
|
||||
formatter_2->format(msg, formatted_2);
|
||||
REQUIRE(fmt::to_string(formatted_1) == fmt::to_string(formatted_2));
|
||||
@@ -263,7 +264,7 @@ static const char *test_path = "/a/b//myfile.cpp";
|
||||
TEST_CASE("short filename formatter-1", "[pattern_formatter]")
|
||||
{
|
||||
spdlog::pattern_formatter formatter("%s", spdlog::pattern_time_type::local, "");
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
std::string logger_name = "logger-name";
|
||||
spdlog::source_loc source_loc{test_path, 123, "some_func()"};
|
||||
spdlog::details::log_msg msg(source_loc, "logger-name", spdlog::level::info, "Hello");
|
||||
@@ -274,7 +275,7 @@ TEST_CASE("short filename formatter-1", "[pattern_formatter]")
|
||||
TEST_CASE("short filename formatter-2", "[pattern_formatter]")
|
||||
{
|
||||
spdlog::pattern_formatter formatter("%s:%#", spdlog::pattern_time_type::local, "");
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
std::string logger_name = "logger-name";
|
||||
spdlog::source_loc source_loc{"myfile.cpp", 123, "some_func()"};
|
||||
spdlog::details::log_msg msg(source_loc, "logger-name", spdlog::level::info, "Hello");
|
||||
@@ -285,7 +286,7 @@ TEST_CASE("short filename formatter-2", "[pattern_formatter]")
|
||||
TEST_CASE("short filename formatter-3", "[pattern_formatter]")
|
||||
{
|
||||
spdlog::pattern_formatter formatter("%s %v", spdlog::pattern_time_type::local, "");
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
std::string logger_name = "logger-name";
|
||||
spdlog::source_loc source_loc{"", 123, "some_func()"};
|
||||
spdlog::details::log_msg msg(source_loc, "logger-name", spdlog::level::info, "Hello");
|
||||
@@ -296,7 +297,7 @@ TEST_CASE("short filename formatter-3", "[pattern_formatter]")
|
||||
TEST_CASE("full filename formatter", "[pattern_formatter]")
|
||||
{
|
||||
spdlog::pattern_formatter formatter("%g", spdlog::pattern_time_type::local, "");
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
std::string logger_name = "logger-name";
|
||||
spdlog::source_loc source_loc{test_path, 123, "some_func()"};
|
||||
spdlog::details::log_msg msg(source_loc, "logger-name", spdlog::level::info, "Hello");
|
||||
|
@@ -49,7 +49,7 @@ public:
|
||||
protected:
|
||||
void sink_it_(const details::log_msg &msg) override
|
||||
{
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
base_sink<Mutex>::formatter_->format(msg, formatted);
|
||||
// save the line without the eol
|
||||
auto eol_len = strlen(details::os::default_eol);
|
||||
|
Reference in New Issue
Block a user