From a32cea24fd89705cccb555f49469be0d61dcd4ed Mon Sep 17 00:00:00 2001 From: steven lunt Date: Tue, 18 May 2021 19:24:44 -0400 Subject: [PATCH 1/5] Revert "remove constexpr on level_string_views to fix compilation on C++17 from addition of set_string_view" This reverts commit ac3e26b0ffeffe1f9b030fabdfcb124dc878480e. --- include/spdlog/common-inl.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/spdlog/common-inl.h b/include/spdlog/common-inl.h index d0c85c6b..84e5cf41 100644 --- a/include/spdlog/common-inl.h +++ b/include/spdlog/common-inl.h @@ -13,6 +13,9 @@ namespace spdlog { namespace level { +#if __cplusplus >= 201703L +constexpr +#endif static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES; static const char *short_level_names[] SPDLOG_SHORT_LEVEL_NAMES; From ab72de5f7a3102880d363e6af5910a3f0705bcb1 Mon Sep 17 00:00:00 2001 From: steven lunt Date: Tue, 18 May 2021 19:25:07 -0400 Subject: [PATCH 2/5] Revert "added spdlog::level::set_string_view to enable alternate log level names without changing the build via SPDLOG_LEVEL_NAMES" This reverts commit 2a16d1d2303164618694361513f2ec1391d8f3e4. --- include/spdlog/common-inl.h | 5 ----- include/spdlog/common.h | 1 - tests/test_misc.cpp | 8 -------- 3 files changed, 14 deletions(-) diff --git a/include/spdlog/common-inl.h b/include/spdlog/common-inl.h index 84e5cf41..c3e99222 100644 --- a/include/spdlog/common-inl.h +++ b/include/spdlog/common-inl.h @@ -25,11 +25,6 @@ SPDLOG_INLINE const string_view_t &to_string_view(spdlog::level::level_enum l) S return level_string_views[l]; } -SPDLOG_INLINE void set_string_view(spdlog::level::level_enum l, const string_view_t &s) SPDLOG_NOEXCEPT -{ - level_string_views[l] = s; -} - SPDLOG_INLINE const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT { return short_level_names[l]; diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 95f3719e..0573d525 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -168,7 +168,6 @@ enum level_enum #endif SPDLOG_API const string_view_t &to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT; -SPDLOG_API void set_string_view(spdlog::level::level_enum l, const string_view_t &s) SPDLOG_NOEXCEPT; SPDLOG_API const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT; SPDLOG_API spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCEPT; diff --git a/tests/test_misc.cpp b/tests/test_misc.cpp index 658fe068..1d67e879 100644 --- a/tests/test_misc.cpp +++ b/tests/test_misc.cpp @@ -55,14 +55,6 @@ TEST_CASE("level_to_string_view", "[convert_to_string_view") REQUIRE(spdlog::level::to_string_view(spdlog::level::off) == "off"); } -TEST_CASE("set_level_to_string_view", "[set_string_view") -{ - spdlog::level::set_string_view(spdlog::level::info, "INF"); - REQUIRE(spdlog::level::to_string_view(spdlog::level::info) == "INF"); - spdlog::level::set_string_view(spdlog::level::info, "info"); // set it back - REQUIRE(spdlog::level::to_string_view(spdlog::level::info) == "info"); -} - TEST_CASE("to_short_c_str", "[convert_to_short_c_str]") { REQUIRE(std::string(spdlog::level::to_short_c_str(spdlog::level::trace)) == "T"); From ee22eed23d8ab9ea1efa56d0cb55048e53012ee1 Mon Sep 17 00:00:00 2001 From: steven lunt Date: Tue, 18 May 2021 19:36:45 -0400 Subject: [PATCH 3/5] add macros for overriding the individual level names --- include/spdlog/common.h | 30 ++++++++++++++++++++++++++- include/spdlog/tweakme.h | 44 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 0573d525..dee5baca 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -152,10 +152,38 @@ enum level_enum n_levels }; +#if !defined(SPDLOG_LEVEL_NAME_TRACE) +#define SPDLOG_LEVEL_NAME_TRACE "trace" +#endif + +#if !defined(SPDLOG_LEVEL_NAME_DEBUG) +#define SPDLOG_LEVEL_NAME_DEBUG "debug" +#endif + +#if !defined(SPDLOG_LEVEL_NAME_INFO) +#define SPDLOG_LEVEL_NAME_INFO "info" +#endif + +#if !defined(SPDLOG_LEVEL_NAME_WARNING) +#define SPDLOG_LEVEL_NAME_WARNING "warning" +#endif + +#if !defined(SPDLOG_LEVEL_NAME_ERROR) +#define SPDLOG_LEVEL_NAME_ERROR "error" +#endif + +#if !defined(SPDLOG_LEVEL_NAME_CRITICAL) +#define SPDLOG_LEVEL_NAME_CRITICAL "critical" +#endif + +#if !defined(SPDLOG_LEVEL_NAME_OFF) +#define SPDLOG_LEVEL_NAME_OFF "off" +#endif + #if !defined(SPDLOG_LEVEL_NAMES) #define SPDLOG_LEVEL_NAMES \ { \ - "trace", "debug", "info", "warning", "error", "critical", "off" \ + SPDLOG_LEVEL_NAME_TRACE, SPDLOG_LEVEL_NAME_DEBUG, SPDLOG_LEVEL_NAME_INFO, SPDLOG_LEVEL_NAME_WARNING, SPDLOG_LEVEL_NAME_ERROR, SPDLOG_LEVEL_NAME_CRITICAL, SPDLOG_LEVEL_NAME_OFF \ } #endif diff --git a/include/spdlog/tweakme.h b/include/spdlog/tweakme.h index 31e417ab..87c3d5fa 100644 --- a/include/spdlog/tweakme.h +++ b/include/spdlog/tweakme.h @@ -87,12 +87,54 @@ /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// -// Uncomment to customize level names (e.g. "MT TRACE") +// Uncomment to customize level names (e.g. "MY TRACE") // // #define SPDLOG_LEVEL_NAMES { "MY TRACE", "MY DEBUG", "MY INFO", "MY WARNING", // "MY ERROR", "MY CRITICAL", "OFF" } /////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +// Uncomment to customize the trace level name +// +// #define SPDLOG_LEVEL_NAME_TRACE "MY TRACE" +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +// Uncomment to customize the debug level name +// +// #define SPDLOG_LEVEL_NAME_DEBUG "MY DEBUG" +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +// Uncomment to customize the info level name +// +// #define SPDLOG_LEVEL_NAME_INFO "MY INFO" +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +// Uncomment to customize the warning level name +// +// #define SPDLOG_LEVEL_NAME_WARNING "MY WARNING" +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +// Uncomment to customize the error level name +// +// #define SPDLOG_LEVEL_NAME_ERROR "MY ERROR" +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +// Uncomment to customize the critical level name +// +// #define SPDLOG_LEVEL_NAME_CRITICAL "MY CRITICAL" +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +// Uncomment to customize the off level name +// +// #define SPDLOG_LEVEL_NAME_OFF "MY OFF" +/////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////// // Uncomment to customize short level names (e.g. "MT") // These can be longer than one character. From 802eaadd2d52563e1bb91272dcc5104c6ebebe8a Mon Sep 17 00:00:00 2001 From: steven lunt Date: Wed, 19 May 2021 10:45:33 -0400 Subject: [PATCH 4/5] add macros for overriding the individual level names --- CMakeLists.txt | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6258defd..56dcd41b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -235,6 +235,38 @@ if(SPDLOG_NO_EXCEPTIONS AND NOT MSVC) target_compile_options(spdlog PRIVATE -fno-exceptions) endif() +# --------------------------------------------------------------------------------------- +# Allow override of level names +# --------------------------------------------------------------------------------------- +if(NOT SPDLOG_LEVEL_NAME_TRACE) + set(SPDLOG_LEVEL_NAME_TRACE trace) +endif() +if(NOT SPDLOG_LEVEL_NAME_DEBUG) + set(SPDLOG_LEVEL_NAME_DEBUG debug) +endif() +if(NOT SPDLOG_LEVEL_NAME_INFO) + set(SPDLOG_LEVEL_NAME_INFO info) +endif() +if(NOT SPDLOG_LEVEL_NAME_WARNING) + set(SPDLOG_LEVEL_NAME_WARNING warning) +endif() +if(NOT SPDLOG_LEVEL_NAME_ERROR) + set(SPDLOG_LEVEL_NAME_ERROR error) +endif() +if(NOT SPDLOG_LEVEL_NAME_CRITICAL) + set(SPDLOG_LEVEL_NAME_CRITICAL critical) +endif() +if(NOT SPDLOG_LEVEL_NAME_OFF) + set(SPDLOG_LEVEL_NAME_OFF off) +endif() +target_compile_definitions(spdlog PUBLIC SPDLOG_LEVEL_NAME_TRACE=\"${SPDLOG_LEVEL_NAME_TRACE}\") +target_compile_definitions(spdlog PUBLIC SPDLOG_LEVEL_NAME_DEBUG=\"${SPDLOG_LEVEL_NAME_DEBUG}\") +target_compile_definitions(spdlog PUBLIC SPDLOG_LEVEL_NAME_INFO=\"${SPDLOG_LEVEL_NAME_INFO}\") +target_compile_definitions(spdlog PUBLIC SPDLOG_LEVEL_NAME_WARNING=\"${SPDLOG_LEVEL_NAME_WARNING}\") +target_compile_definitions(spdlog PUBLIC SPDLOG_LEVEL_NAME_ERROR=\"${SPDLOG_LEVEL_NAME_ERROR}\") +target_compile_definitions(spdlog PUBLIC SPDLOG_LEVEL_NAME_CRITICAL=\"${SPDLOG_LEVEL_NAME_CRITICAL}\") +target_compile_definitions(spdlog PUBLIC SPDLOG_LEVEL_NAME_OFF=\"${SPDLOG_LEVEL_NAME_OFF}\") + # --------------------------------------------------------------------------------------- # Build binaries # --------------------------------------------------------------------------------------- From 1bee3218b4f72cfe3aa85d63c92545385ec4593b Mon Sep 17 00:00:00 2001 From: steven lunt Date: Wed, 19 May 2021 17:51:03 -0400 Subject: [PATCH 5/5] cleanup thanks to gabime --- CMakeLists.txt | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 56dcd41b..1132417f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -238,27 +238,14 @@ endif() # --------------------------------------------------------------------------------------- # Allow override of level names # --------------------------------------------------------------------------------------- -if(NOT SPDLOG_LEVEL_NAME_TRACE) - set(SPDLOG_LEVEL_NAME_TRACE trace) -endif() -if(NOT SPDLOG_LEVEL_NAME_DEBUG) - set(SPDLOG_LEVEL_NAME_DEBUG debug) -endif() -if(NOT SPDLOG_LEVEL_NAME_INFO) - set(SPDLOG_LEVEL_NAME_INFO info) -endif() -if(NOT SPDLOG_LEVEL_NAME_WARNING) - set(SPDLOG_LEVEL_NAME_WARNING warning) -endif() -if(NOT SPDLOG_LEVEL_NAME_ERROR) - set(SPDLOG_LEVEL_NAME_ERROR error) -endif() -if(NOT SPDLOG_LEVEL_NAME_CRITICAL) - set(SPDLOG_LEVEL_NAME_CRITICAL critical) -endif() -if(NOT SPDLOG_LEVEL_NAME_OFF) - set(SPDLOG_LEVEL_NAME_OFF off) -endif() +set(SPDLOG_LEVEL_NAME_TRACE "trace" CACHE STRING "custom level name") +set(SPDLOG_LEVEL_NAME_DEBUG "debug" CACHE STRING "custom level name") +set(SPDLOG_LEVEL_NAME_INFO "info" CACHE STRING "custom level name") +set(SPDLOG_LEVEL_NAME_WARNING "warning" CACHE STRING "custom level name") +set(SPDLOG_LEVEL_NAME_ERROR "error" CACHE STRING "custom level name") +set(SPDLOG_LEVEL_NAME_CRITICAL "critical" CACHE STRING "custom level name") +set(SPDLOG_LEVEL_NAME_OFF "off" CACHE STRING "custom level name") + target_compile_definitions(spdlog PUBLIC SPDLOG_LEVEL_NAME_TRACE=\"${SPDLOG_LEVEL_NAME_TRACE}\") target_compile_definitions(spdlog PUBLIC SPDLOG_LEVEL_NAME_DEBUG=\"${SPDLOG_LEVEL_NAME_DEBUG}\") target_compile_definitions(spdlog PUBLIC SPDLOG_LEVEL_NAME_INFO=\"${SPDLOG_LEVEL_NAME_INFO}\")