From e3f8349d0c6c70f5ad99bd6b03671560b0ed0867 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Sat, 18 Jan 2025 07:32:30 +0200 Subject: [PATCH] Add missing locks to ansicolor_sink.cpp --- src/sinks/ansicolor_sink.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/sinks/ansicolor_sink.cpp b/src/sinks/ansicolor_sink.cpp index ce6e7154..6de54e50 100644 --- a/src/sinks/ansicolor_sink.cpp +++ b/src/sinks/ansicolor_sink.cpp @@ -12,10 +12,7 @@ namespace spdlog { namespace sinks { template -ansicolor_sink::ansicolor_sink(FILE *target_file, color_mode mode) - : target_file_(target_file) - -{ +ansicolor_sink::ansicolor_sink(FILE *target_file, color_mode mode) : target_file_(target_file) { set_color_mode(mode); colors_.at(level_to_number(level::trace)) = to_string_(white); colors_.at(level_to_number(level::debug)) = to_string_(cyan); @@ -34,11 +31,13 @@ void ansicolor_sink::set_color(level color_level, string_view_t color) { template bool ansicolor_sink::should_color() const { + std::lock_guard lock(base_sink::mutex_); return should_do_colors_; } template void ansicolor_sink::set_color_mode(color_mode mode) { + std::lock_guard lock(base_sink::mutex_); switch (mode) { case color_mode::always: should_do_colors_ = true; @@ -58,7 +57,6 @@ template void ansicolor_sink::sink_it_(const details::log_msg &msg) { // Wrap the originally formatted message in color codes. // If color is not supported in the terminal, log as is instead. - msg.color_range_start = 0; msg.color_range_end = 0; memory_buf_t formatted;