From 83d5f3dbadb54290bc8cd69dd35b126bd2b999f8 Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 21 Oct 2023 13:56:34 +0300 Subject: [PATCH] Revert 70f7a8252d0a4284d7d05c305648798843f50d23 --- example/example.cpp | 2 +- include/spdlog/common.h | 10 ++++++++-- tests/test_errors.cpp | 6 +++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/example/example.cpp b/example/example.cpp index 16c0e3aa9..1b74f6d1e 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -170,7 +170,7 @@ void async_example() { // {:n} - don't split the output to lines. #if !defined SPDLOG_USE_STD_FORMAT || defined(_MSC_VER) -#include "spdlog/fmt/bin_to_hex.h" + #include "spdlog/fmt/bin_to_hex.h" void binary_example() { std::vector buf(80); for (int i = 0; i < 80; i++) { diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 1f09040be..191e6ec0e 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -42,8 +42,14 @@ #include "fmt/fmt.h" -#if defined(SPDLOG_WCHAR_FILENAMES) && !defined(SPDLOG_USE_STD_FORMAT) - #include "fmt/xchar.h" +#if !defined(SPDLOG_USE_STD_FORMAT) && \ + FMT_VERSION >= 80000 // backward compatibility with fmt versions older than 8 + #define SPDLOG_FMT_RUNTIME(format_string) fmt::runtime(format_string) + #if defined(SPDLOG_WCHAR_FILENAMES) + #include "fmt/xchar.h" + #endif +#else + #define SPDLOG_FMT_RUNTIME(format_string) format_string #endif #ifndef SPDLOG_FUNCTION diff --git a/tests/test_errors.cpp b/tests/test_errors.cpp index 5b2d7abc8..448cb7b2f 100644 --- a/tests/test_errors.cpp +++ b/tests/test_errors.cpp @@ -27,7 +27,7 @@ TEST_CASE("default_error_handler", "[errors]") { auto logger = spdlog::create("test-error", filename, true); logger->set_pattern("%v"); - logger->info("Test message {} {}", 1); + logger->info(SPDLOG_FMT_RUNTIME("Test message {} {}"), 1); logger->info("Test message {}", 2); logger->flush(); using spdlog::details::os::default_eol; @@ -43,7 +43,7 @@ TEST_CASE("custom_error_handler", "[errors]") { logger->set_error_handler([=](const std::string &) { throw custom_ex(); }); logger->info("Good message #1"); - REQUIRE_THROWS_AS(logger->info("Bad format msg {} {}", "xxx"), custom_ex); + REQUIRE_THROWS_AS(logger->info(SPDLOG_FMT_RUNTIME("Bad format msg {} {}"), "xxx"), custom_ex); logger->info("Good message #2"); require_message_count(SIMPLE_LOG, 2); } @@ -81,7 +81,7 @@ TEST_CASE("async_error_handler", "[errors]") { ofs << err_msg; }); logger->info("Good message #1"); - logger->info("Bad format msg {} {}", "xxx"); + logger->info(SPDLOG_FMT_RUNTIME("Bad format msg {} {}"), "xxx"); logger->info("Good message #2"); spdlog::drop("logger"); // force logger to drain the queue and shutdown }