From 0b36d4e360ad89b30bf9c57d208542a0486cc587 Mon Sep 17 00:00:00 2001 From: gabime Date: Tue, 5 May 2020 01:03:33 +0300 Subject: [PATCH] Fix #1540 --- include/spdlog/sinks/ansicolor_sink-inl.h | 22 ++++++++++++++-------- include/spdlog/sinks/ansicolor_sink.h | 3 ++- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/include/spdlog/sinks/ansicolor_sink-inl.h b/include/spdlog/sinks/ansicolor_sink-inl.h index 288aeced..aca4dffb 100644 --- a/include/spdlog/sinks/ansicolor_sink-inl.h +++ b/include/spdlog/sinks/ansicolor_sink-inl.h @@ -21,20 +21,20 @@ SPDLOG_INLINE ansicolor_sink::ansicolor_sink(FILE *target_file, co { set_color_mode(mode); - colors_[level::trace] = white; - colors_[level::debug] = cyan; - colors_[level::info] = green; - colors_[level::warn] = yellow_bold; - colors_[level::err] = red_bold; - colors_[level::critical] = bold_on_red; - colors_[level::off] = reset; + colors_[level::trace] = to_string_(white); + colors_[level::debug] = to_string_(cyan); + colors_[level::info] = to_string_(green); + colors_[level::warn] = to_string_(yellow_bold); + colors_[level::err] = to_string_(red_bold); + colors_[level::critical] = to_string_(bold_on_red); + colors_[level::off] = to_string_(reset); } template SPDLOG_INLINE void ansicolor_sink::set_color(level::level_enum color_level, string_view_t color) { std::lock_guard lock(mutex_); - colors_[color_level] = color; + colors_[color_level] = to_string_(color); } template @@ -121,6 +121,12 @@ SPDLOG_INLINE void ansicolor_sink::print_range_(const memory_buf_t fwrite(formatted.data() + start, sizeof(char), end - start, target_file_); } +template +SPDLOG_INLINE std::string ansicolor_sink::to_string_(const string_view_t& sv) +{ + return std::string(sv.data(), sv.size()); +} + // ansicolor_stdout_sink template SPDLOG_INLINE ansicolor_stdout_sink::ansicolor_stdout_sink(color_mode mode) diff --git a/include/spdlog/sinks/ansicolor_sink.h b/include/spdlog/sinks/ansicolor_sink.h index 90b590e6..3dba7e85 100644 --- a/include/spdlog/sinks/ansicolor_sink.h +++ b/include/spdlog/sinks/ansicolor_sink.h @@ -84,9 +84,10 @@ private: mutex_t &mutex_; bool should_do_colors_; std::unique_ptr formatter_; - std::array colors_; + std::array colors_; void print_ccode_(const string_view_t &color_code); void print_range_(const memory_buf_t &formatted, size_t start, size_t end); + std::string to_string_(const string_view_t& sv); }; template