From ea896885cdb4407b1803033ecb2fb5c11662adc0 Mon Sep 17 00:00:00 2001 From: gabime Date: Fri, 29 Nov 2024 14:57:11 +0200 Subject: [PATCH] Removed SPDLOG_USE_STD_FORMAT --- .github/workflows/windows.yml | 6 ++---- bench/bench.cpp | 7 +------ cmake/spdlogConfig.cmake.in | 5 +---- cmake/spdlog_config.h.in | 4 ---- src/common.cpp | 4 ---- tests/CMakeLists.txt | 7 ++----- tests/test_daily_and_rotation_loggers.cpp | 6 +----- tests/test_errors.cpp | 5 +---- 8 files changed, 8 insertions(+), 36 deletions(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 60c04e82..a7a651dd 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -56,8 +56,7 @@ jobs: -D SPDLOG_WCHAR_FILENAMES=${{ matrix.config.WCHAR_FILES }} ` -D SPDLOG_BUILD_EXAMPLE=${{ matrix.config.BUILD_EXAMPLE }} ` -D SPDLOG_BUILD_TESTS=ON ` - -D SPDLOG_BUILD_WARNINGS=${{ matrix.config.FATAL_ERRORS }} ` - -D SPDLOG_USE_STD_FORMAT=${{ matrix.config.USE_STD_FORMAT }} ` + -D SPDLOG_BUILD_WARNINGS=${{ matrix.config.FATAL_ERRORS }} ` -D CMAKE_CXX_STANDARD=${{ matrix.config.CXX_STANDARD }} .. - name: Build @@ -117,8 +116,7 @@ jobs: -D SPDLOG_WCHAR_FILENAMES=${{ matrix.config.WCHAR_FILES }} ` -D SPDLOG_BUILD_EXAMPLE=${{ matrix.config.BUILD_EXAMPLE }} ` -D SPDLOG_BUILD_TESTS=ON ` - -D SPDLOG_BUILD_WARNINGS=${{ matrix.config.FATAL_ERRORS }} ` - -D SPDLOG_USE_STD_FORMAT=${{ matrix.config.USE_STD_FORMAT }} ` + -D SPDLOG_BUILD_WARNINGS=${{ matrix.config.FATAL_ERRORS }} ` -D CMAKE_CXX_STANDARD=${{ matrix.config.CXX_STANDARD }} .. - name: Build diff --git a/bench/bench.cpp b/bench/bench.cpp index 8781e647..c21a1158 100644 --- a/bench/bench.cpp +++ b/bench/bench.cpp @@ -12,12 +12,7 @@ #include "spdlog/sinks/rotating_file_sink.h" #include "spdlog/spdlog.h" -#if defined(SPDLOG_USE_STD_FORMAT) - #include -#else - #include -#endif - +#include #include #include // EXIT_FAILURE #include diff --git a/cmake/spdlogConfig.cmake.in b/cmake/spdlogConfig.cmake.in index fdd4fb26..47866bb4 100644 --- a/cmake/spdlogConfig.cmake.in +++ b/cmake/spdlogConfig.cmake.in @@ -7,10 +7,7 @@ include(CMakeFindDependencyMacro) find_package(Threads REQUIRED) -set(SPDLOG_USE_STD_FORMAT @SPDLOG_USE_STD_FORMAT@) -if(NOT SPDLOG_USE_STD_FORMAT) - find_dependency(fmt CONFIG) -endif() +find_dependency(fmt CONFIG) set(config_targets_file @config_targets_file@) include("${CMAKE_CURRENT_LIST_DIR}/${config_targets_file}") diff --git a/cmake/spdlog_config.h.in b/cmake/spdlog_config.h.in index fedafae5..4dfdd820 100644 --- a/cmake/spdlog_config.h.in +++ b/cmake/spdlog_config.h.in @@ -27,9 +27,5 @@ // Disable default logger creation #cmakedefine SPDLOG_DISABLE_DEFAULT_LOGGER -// Use std::format instead of fmtlib -#cmakedefine SPDLOG_USE_STD_FORMAT - // Use external fmtlib instead of bundled #cmakedefine SPDLOG_FMT_EXTERNAL - diff --git a/src/common.cpp b/src/common.cpp index 1a7c24ad..c847eafd 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -26,13 +26,9 @@ spdlog_ex::spdlog_ex(std::string msg) : msg_(std::move(msg)) {} spdlog_ex::spdlog_ex(const std::string &msg, int last_errno) { -#ifdef SPDLOG_USE_STD_FORMAT - msg_ = std::system_error(std::error_code(last_errno, std::generic_category()), msg).what(); -#else memory_buf_t outbuf; fmt::format_system_error(outbuf, last_errno, msg.c_str()); msg_ = fmt::to_string(outbuf); -#endif } const char *spdlog_ex::what() const noexcept { return msg_.c_str(); } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5456a4fd..fa245b97 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -52,7 +52,8 @@ set(SPDLOG_UTESTS_SOURCES test_source_location.cpp test_no_source_location.cpp test_log_level.cpp - test_include_sinks.cpp) + test_include_sinks.cpp + test_bin_to_hex.cpp) if(WIN32) list(APPEND SPDLOG_UTESTS_SOURCES test_eventlog.cpp) @@ -66,10 +67,6 @@ if(systemd_FOUND) list(APPEND SPDLOG_UTESTS_SOURCES test_systemd.cpp) endif() -if(NOT SPDLOG_USE_STD_FORMAT) - list(APPEND SPDLOG_UTESTS_SOURCES test_bin_to_hex.cpp) -endif() - enable_testing() function(spdlog_prepare_test test_target spdlog_lib) diff --git a/tests/test_daily_and_rotation_loggers.cpp b/tests/test_daily_and_rotation_loggers.cpp index 7d96a79d..dad43795 100644 --- a/tests/test_daily_and_rotation_loggers.cpp +++ b/tests/test_daily_and_rotation_loggers.cpp @@ -6,11 +6,7 @@ #include "spdlog/sinks/daily_file_sink.h" #include "spdlog/sinks/rotating_file_sink.h" -#ifdef SPDLOG_USE_STD_FORMAT -using filename_memory_buf_t = std::basic_string; -#else -using filename_memory_buf_t = fmt::basic_memory_buffer; -#endif +using filename_memory_buf_t = spdlog::memory_buf_t; #ifdef SPDLOG_WCHAR_FILENAMES std::string filename_buf_to_utf8string(const filename_memory_buf_t &w) { diff --git a/tests/test_errors.cpp b/tests/test_errors.cpp index 06a0368e..0f164b0a 100644 --- a/tests/test_errors.cpp +++ b/tests/test_errors.cpp @@ -18,7 +18,7 @@ protected: }; struct custom_ex {}; -#if !defined(SPDLOG_USE_STD_FORMAT) // std formt doesn't fully support runtime format strings + TEST_CASE("default_error_handler", "[errors]") { prepare_logdir(); spdlog::filename_t filename = SPDLOG_FILENAME_T(SIMPLE_LOG); @@ -45,7 +45,6 @@ TEST_CASE("custom_error_handler", "[errors]") { logger->info("Good message #2"); require_message_count(SIMPLE_LOG, 2); } -#endif TEST_CASE("default_error_handler2", "[errors]") { spdlog::drop_all(); @@ -61,7 +60,6 @@ TEST_CASE("flush_error_handler", "[errors]") { REQUIRE_THROWS_AS(logger->flush(), custom_ex); } -#if !defined(SPDLOG_USE_STD_FORMAT) // std formt doesn't fully support runtime format strings TEST_CASE("async_error_handler", "[errors]") { prepare_logdir(); std::string err_msg("log failed with some msg"); @@ -86,7 +84,6 @@ TEST_CASE("async_error_handler", "[errors]") { require_message_count(SIMPLE_ASYNC_LOG, 2); REQUIRE(file_contents("test_logs/custom_err.txt") == err_msg); } -#endif // Make sure async error handler is executed TEST_CASE("async_error_handler2", "[errors]") {