From d94311ad6b837634132f2fae14f107c809b8cc2d Mon Sep 17 00:00:00 2001 From: gabime Date: Tue, 26 Nov 2024 13:35:01 +0200 Subject: [PATCH] Use std::string_view in level names and ansicolor_sink.h --- include/spdlog/common.h | 8 ++-- include/spdlog/sinks/ansicolor_sink.h | 54 +++++++++++++-------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 2e373438..20dfdb06 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -158,15 +158,15 @@ using atomic_level_t = std::atomic; [[nodiscard]] constexpr size_t level_to_number(level lvl) noexcept { return static_cast(lvl); } constexpr auto levels_count = level_to_number(level::n_levels); -constexpr std::array level_string_views{"trace", "debug", "info", "warning", +constexpr std::array level_string_views{"trace", "debug", "info", "warning", "error", "critical", "off"}; -constexpr std::array short_level_names{"T", "D", "I", "W", "E", "C", "O"}; +constexpr std::array short_level_names{"T", "D", "I", "W", "E", "C", "O"}; -[[nodiscard]] constexpr string_view_t to_string_view(spdlog::level lvl) noexcept { +[[nodiscard]] constexpr std::string_view to_string_view(spdlog::level lvl) noexcept { return level_string_views.at(level_to_number(lvl)); } -[[nodiscard]] constexpr const string_view_t to_short_string_view(spdlog::level lvl) noexcept { +[[nodiscard]] constexpr const std::string_view to_short_string_view(spdlog::level lvl) noexcept { return short_level_names.at(level_to_number(lvl)); } diff --git a/include/spdlog/sinks/ansicolor_sink.h b/include/spdlog/sinks/ansicolor_sink.h index 1e8dd1b2..46ce2159 100644 --- a/include/spdlog/sinks/ansicolor_sink.h +++ b/include/spdlog/sinks/ansicolor_sink.h @@ -35,39 +35,39 @@ public: bool should_color(); // Formatting codes - static constexpr spdlog::string_view_t reset = "\033[m"; - static constexpr spdlog::string_view_t bold = "\033[1m"; - static constexpr spdlog::string_view_t dark = "\033[2m"; - static constexpr spdlog::string_view_t underline = "\033[4m"; - static constexpr spdlog::string_view_t blink = "\033[5m"; - static constexpr spdlog::string_view_t reverse = "\033[7m"; - static constexpr spdlog::string_view_t concealed = "\033[8m"; - static constexpr spdlog::string_view_t clear_line = "\033[K"; + static constexpr std::string_view reset = "\033[m"; + static constexpr std::string_view bold = "\033[1m"; + static constexpr std::string_view dark = "\033[2m"; + static constexpr std::string_view underline = "\033[4m"; + static constexpr std::string_view blink = "\033[5m"; + static constexpr std::string_view reverse = "\033[7m"; + static constexpr std::string_view concealed = "\033[8m"; + static constexpr std::string_view clear_line = "\033[K"; // Foreground colors - static constexpr spdlog::string_view_t black = "\033[30m"; - static constexpr spdlog::string_view_t red = "\033[31m"; - static constexpr spdlog::string_view_t green = "\033[32m"; - static constexpr spdlog::string_view_t yellow = "\033[33m"; - static constexpr spdlog::string_view_t blue = "\033[34m"; - static constexpr spdlog::string_view_t magenta = "\033[35m"; - static constexpr spdlog::string_view_t cyan = "\033[36m"; - static constexpr spdlog::string_view_t white = "\033[37m"; + static constexpr std::string_view black = "\033[30m"; + static constexpr std::string_view red = "\033[31m"; + static constexpr std::string_view green = "\033[32m"; + static constexpr std::string_view yellow = "\033[33m"; + static constexpr std::string_view blue = "\033[34m"; + static constexpr std::string_view magenta = "\033[35m"; + static constexpr std::string_view cyan = "\033[36m"; + static constexpr std::string_view white = "\033[37m"; // Background colors - static constexpr spdlog::string_view_t on_black = "\033[40m"; - static constexpr spdlog::string_view_t on_red = "\033[41m"; - static constexpr spdlog::string_view_t on_green = "\033[42m"; - static constexpr spdlog::string_view_t on_yellow = "\033[43m"; - static constexpr spdlog::string_view_t on_blue = "\033[44m"; - static constexpr spdlog::string_view_t on_magenta = "\033[45m"; - static constexpr spdlog::string_view_t on_cyan = "\033[46m"; - static constexpr spdlog::string_view_t on_white = "\033[47m"; + static constexpr std::string_view on_black = "\033[40m"; + static constexpr std::string_view on_red = "\033[41m"; + static constexpr std::string_view on_green = "\033[42m"; + static constexpr std::string_view on_yellow = "\033[43m"; + static constexpr std::string_view on_blue = "\033[44m"; + static constexpr std::string_view on_magenta = "\033[45m"; + static constexpr std::string_view on_cyan = "\033[46m"; + static constexpr std::string_view on_white = "\033[47m"; // Bold colors - static constexpr spdlog::string_view_t yellow_bold = "\033[33m\033[1m"; - static constexpr spdlog::string_view_t red_bold = "\033[31m\033[1m"; - static constexpr spdlog::string_view_t bold_on_red = "\033[1m\033[41m"; + static constexpr std::string_view yellow_bold = "\033[33m\033[1m"; + static constexpr std::string_view red_bold = "\033[31m\033[1m"; + static constexpr std::string_view bold_on_red = "\033[1m\033[41m"; private: void sink_it_(const details::log_msg &msg) override;