Commit 1b04c222 authored by gabime's avatar gabime

Fixed issue #888

parent 5d048488
......@@ -15,7 +15,6 @@ namespace spdlog {
namespace details {
struct log_msg
{
log_msg() = default;
log_msg(const std::string *loggers_name, level::level_enum lvl, string_view_t view)
: logger_name(loggers_name)
......@@ -38,9 +37,9 @@ struct log_msg
level::level_enum level{level::off};
log_clock::time_point time;
size_t thread_id{0};
size_t msg_id;
size_t msg_id{0};
// info about wrapping the formatted text with color (updated by pattern_formatter).
// wrapping the formatted text with color (updated by pattern_formatter).
mutable size_t color_range_start{0};
mutable size_t color_range_end{0};
......
......@@ -82,12 +82,17 @@ struct async_msg
}
async_msg(async_logger_ptr &&worker, async_msg_type the_type)
: async_msg(std::move(worker), the_type, details::log_msg())
: msg_type(the_type)
, level(level::off)
, time()
, thread_id(0)
, msg_id(0)
, worker_ptr(std::move(worker))
{
}
explicit async_msg(async_msg_type the_type)
: async_msg(nullptr, the_type, details::log_msg())
: async_msg(nullptr, the_type)
{
}
......
......@@ -10,7 +10,6 @@ static const std::string target_filename = "logs/file_helper_test.txt";
static void write_with_helper(file_helper &helper, size_t howmany)
{
log_msg msg;
fmt::memory_buffer formatted;
fmt::format_to(formatted, "{}", std::string(howmany, '1'));
helper.write(formatted);
......
......@@ -75,7 +75,8 @@ TEST_CASE("color range test1", "[pattern_formatter]")
TEST_CASE("color range test2", "[pattern_formatter]")
{
auto formatter = std::make_shared<spdlog::pattern_formatter>("%^%$", spdlog::pattern_time_type::local, "\n");
spdlog::details::log_msg msg;
std::string logger_name = "test";
spdlog::details::log_msg msg(&logger_name, spdlog::level::info, "");
fmt::memory_buffer formatted;
formatter->format(msg, formatted);
REQUIRE(msg.color_range_start == 0);
......@@ -86,7 +87,8 @@ TEST_CASE("color range test2", "[pattern_formatter]")
TEST_CASE("color range test3", "[pattern_formatter]")
{
auto formatter = std::make_shared<spdlog::pattern_formatter>("%^***%$");
spdlog::details::log_msg msg;
std::string logger_name = "test";
spdlog::details::log_msg msg(&logger_name, spdlog::level::info, "ignored");
fmt::memory_buffer formatted;
formatter->format(msg, formatted);
REQUIRE(msg.color_range_start == 0);
......@@ -109,7 +111,8 @@ TEST_CASE("color range test4", "[pattern_formatter]")
TEST_CASE("color range test5", "[pattern_formatter]")
{
auto formatter = std::make_shared<spdlog::pattern_formatter>("**%^");
spdlog::details::log_msg msg;
std::string logger_name = "test";
spdlog::details::log_msg msg(&logger_name, spdlog::level::info, "ignored");
fmt::memory_buffer formatted;
formatter->format(msg, formatted);
REQUIRE(msg.color_range_start == 2);
......@@ -119,7 +122,8 @@ TEST_CASE("color range test5", "[pattern_formatter]")
TEST_CASE("color range test6", "[pattern_formatter]")
{
auto formatter = std::make_shared<spdlog::pattern_formatter>("**%$");
spdlog::details::log_msg msg;
std::string logger_name = "test";
spdlog::details::log_msg msg(&logger_name, spdlog::level::info, "ignored");
fmt::memory_buffer formatted;
formatter->format(msg, formatted);
REQUIRE(msg.color_range_start == 0);
......
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