diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 923d9205..18def90b 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -58,26 +58,4 @@ jobs: -DSPDLOG_SANITIZE_ADDRESS=${{ matrix.config.asan || 'OFF' }} \ -DSPDLOG_SANITIZE_THREAD=${{ matrix.config.tsan || 'OFF' }} make -j 4 - ctest -j 4 --output-on-failure - - # ----------------------------------------------------------------------- - # OS X build matrix - # ----------------------------------------------------------------------- - build_osx: - runs-on: macOS-latest - name: "OS X Clang (C++17, Release)" - steps: - - uses: actions/checkout@v4 - - name: Build - run: | - mkdir -p build && cd build - cmake .. \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_CXX_STANDARD=17 \ - -DSPDLOG_BUILD_EXAMPLE=ON \ - -DSPDLOG_BUILD_WARNINGS=ON \ - -DSPDLOG_BUILD_BENCH=OFF \ - -DSPDLOG_BUILD_TESTS=ON \ - -DSPDLOG_SANITIZE_ADDRESS=OFF - make -j 4 - ctest -j 4 --output-on-failure + ctest -j 4 --output-on-failure diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 60c04e82..d5d73fc3 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -57,7 +57,6 @@ jobs: -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 CMAKE_CXX_STANDARD=${{ matrix.config.CXX_STANDARD }} .. - name: Build @@ -118,7 +117,6 @@ jobs: -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 CMAKE_CXX_STANDARD=${{ matrix.config.CXX_STANDARD }} .. - name: Build diff --git a/CMakeLists.txt b/CMakeLists.txt index 784f382a..20f6a7df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,7 +34,6 @@ elseif(CMAKE_CXX_STANDARD LESS 17) endif() set(CMAKE_CXX_STANDARD_REQUIRED ON) - set(CMAKE_CXX_EXTENSIONS OFF) if(CMAKE_SYSTEM_NAME MATCHES "CYGWIN" OR CMAKE_SYSTEM_NAME MATCHES "MSYS" OR CMAKE_SYSTEM_NAME MATCHES "MINGW") @@ -58,7 +57,6 @@ option(SPDLOG_BUILD_ALL "Build all artifacts" OFF) # build shared option option(SPDLOG_BUILD_SHARED "Build shared library" OFF) - # example options option(SPDLOG_BUILD_EXAMPLE "Build example" ${SPDLOG_MASTER_PROJECT}) @@ -77,19 +75,9 @@ option(SPDLOG_BUILD_WARNINGS "Enable compiler warnings" OFF) # install options option(SPDLOG_SYSTEM_INCLUDES "Include as system headers (skip for clang-tidy)." OFF) option(SPDLOG_INSTALL "Generate the install target" ${SPDLOG_MASTER_PROJECT}) -option(SPDLOG_USE_STD_FORMAT "Use std::format instead of fmt library." OFF) option(SPDLOG_FMT_EXTERNAL "Use external fmt library instead of of fetching from gitub." OFF) - option(SPDLOG_NO_EXCEPTIONS "Compile with -fno-exceptions. Call abort() on any spdlog exceptions" OFF) -if(SPDLOG_USE_STD_FORMAT AND CMAKE_CXX_STANDARD LESS 20) - message(FATAL_ERROR "SPDLOG_USE_STD_FORMAT must be used with CMAKE_CXX_STANDARD >= 20") -endif() - -if(SPDLOG_USE_STD_FORMAT AND SPDLOG_FMT_EXTERNAL) - message(FATAL_ERROR "SPDLOG_USE_STD_FORMAT and SPDLOG_FMT_EXTERNAL are mutually exclusive") -endif() - # misc tweakme options if(WIN32) option(SPDLOG_WCHAR_FILENAMES "Support wchar filenames" OFF) @@ -126,35 +114,31 @@ if(SPDLOG_BUILD_SHARED) endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - # place dlls and libs and executables in the same directory - set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$) - set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$) - set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$) - set(CMAKE_PDB_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$) + # place dlls and libs and executables in the same directory + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$) + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$) + set(CMAKE_PDB_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$) - # make sure __cplusplus is defined - add_compile_options(/Zc:__cplusplus) - # enable parallel build for the solution - add_compile_options(/MP) + # make sure __cplusplus is defined + add_compile_options(/Zc:__cplusplus) + # enable parallel build for the solution + add_compile_options(/MP) endif() - message(STATUS "spdlog version: ${SPDLOG_VERSION}") message(STATUS "spdlog build type: " ${CMAKE_BUILD_TYPE}) message(STATUS "spdlog build shared: " ${BUILD_SHARED_LIBS}) -message(STATUS "spdlog use std format: " ${SPDLOG_USE_STD_FORMAT}) message(STATUS "spdlog fmt external: " ${SPDLOG_FMT_EXTERNAL}) # --------------------------------------------------------------------------------------- -# Find {fmt} library if not using std::format +# Find {fmt} library # --------------------------------------------------------------------------------------- -if(NOT SPDLOG_USE_STD_FORMAT) - if (SPDLOG_FMT_EXTERNAL) - find_package(fmt REQUIRED) - message(STATUS "Using external fmt lib version: ${fmt_VERSION}") - else() - include(cmake/fmtlib.cmake) - endif() +if(SPDLOG_FMT_EXTERNAL) + find_package(fmt REQUIRED) + message(STATUS "Using external fmt lib version: ${fmt_VERSION}") +else() + include(cmake/fmtlib.cmake) endif() # --------------------------------------------------------------------------------------- @@ -217,8 +201,7 @@ set(SPDLOG_HEADERS "include/spdlog/sinks/syslog_sink.h" "include/spdlog/sinks/systemd_sink.h" "include/spdlog/sinks/tcp_sink.h" - "include/spdlog/sinks/udp_sink.h" -) + "include/spdlog/sinks/udp_sink.h") set(SPDLOG_SRCS "src/async_logger.cpp" @@ -242,20 +225,18 @@ set(SPDLOG_SRCS "src/sinks/stdout_sinks.cpp") if(WIN32) - list(APPEND SPDLOG_SRCS - "src/details/os_windows.cpp" - "src/sinks/wincolor_sink.cpp") - list(APPEND SPDLOG_HEADERS - "include/spdlog/details/tcp_client_windows.h" - "include/spdlog/details/udp_client_windows.h" - "include/spdlog/details/windows_include.h" - "include/spdlog/sinks/win_eventlog_sink.h" - "include/spdlog/sinks/wincolor_sink.h") + list(APPEND SPDLOG_SRCS "src/details/os_windows.cpp" "src/sinks/wincolor_sink.cpp") + list( + APPEND + SPDLOG_HEADERS + "include/spdlog/details/tcp_client_windows.h" + "include/spdlog/details/udp_client_windows.h" + "include/spdlog/details/windows_include.h" + "include/spdlog/sinks/win_eventlog_sink.h" + "include/spdlog/sinks/wincolor_sink.h") else() list(APPEND SPDLOG_SRCS "src/details/os_unix.cpp") - list(APPEND SPDLOG_HEADERS - "include/spdlog/details/tcp_client_unix.h" - "include/spdlog/details/udp_client_unix.h") + list(APPEND SPDLOG_HEADERS "include/spdlog/details/tcp_client_unix.h" "include/spdlog/details/udp_client_unix.h") endif() # Generate spdlog_config.h based on the current configuration @@ -287,16 +268,14 @@ endif() set_target_properties(spdlog PROPERTIES PUBLIC_HEADER "${SPDLOG_HEADERS}") -target_include_directories(spdlog ${SPDLOG_INCLUDES_LEVEL} PUBLIC - "$" - "$") +target_include_directories(spdlog ${SPDLOG_INCLUDES_LEVEL} PUBLIC "$" + "$") target_link_libraries(spdlog PUBLIC Threads::Threads) -if(NOT SPDLOG_USE_STD_FORMAT) - target_link_libraries(spdlog PUBLIC fmt::fmt) -endif() +target_link_libraries(spdlog PUBLIC fmt::fmt) spdlog_enable_warnings(spdlog) -set_target_properties(spdlog PROPERTIES VERSION ${SPDLOG_VERSION} SOVERSION ${SPDLOG_VERSION_MAJOR}.${SPDLOG_VERSION_MINOR}) +set_target_properties(spdlog PROPERTIES VERSION ${SPDLOG_VERSION} SOVERSION + ${SPDLOG_VERSION_MAJOR}.${SPDLOG_VERSION_MINOR}) set_target_properties(spdlog PROPERTIES DEBUG_POSTFIX d) # set source groups for visual studio @@ -313,7 +292,6 @@ if(ANDROID) target_link_libraries(spdlog PUBLIC log) endif() - # --------------------------------------------------------------------------------------- # If exceptions are disabled, disable them in the bundled fmt as well # --------------------------------------------------------------------------------------- @@ -403,8 +381,7 @@ if(SPDLOG_INSTALL) # --------------------------------------------------------------------------------------- include(cmake/spdlogCPack.cmake) - # Install spdlog_config.h file - # Assume your tweakme.h.in is located in the same directory as CMakeLists.txt + # Install spdlog_config.h file Assume your tweakme.h.in is located in the same directory as CMakeLists.txt set(TWEAKME_IN "${CMAKE_CURRENT_SOURCE_DIR}/tweakme.h.in") set(TWEAKME_OUT "${CMAKE_CURRENT_BINARY_DIR}/include/spdlog/tweakme.h") endif() diff --git a/bench/CMakeLists.txt b/bench/CMakeLists.txt index 4fbce553..a20acda3 100644 --- a/bench/CMakeLists.txt +++ b/bench/CMakeLists.txt @@ -22,7 +22,7 @@ if(NOT benchmark_FOUND) # Do not build and run googlebenchmark tests FetchContent_Declare(googlebenchmark GIT_REPOSITORY https://github.com/google/benchmark.git GIT_TAG v1.6.0) FetchContent_MakeAvailable(googlebenchmark) - set_target_properties(benchmark PROPERTIES FOLDER "third-party") + set_target_properties(benchmark PROPERTIES FOLDER "third-party") endif() add_executable(bench bench.cpp) diff --git a/bench/bench.cpp b/bench/bench.cpp index 8781e647..66d1621d 100644 --- a/bench/bench.cpp +++ b/bench/bench.cpp @@ -6,17 +6,7 @@ // // bench.cpp : spdlog benchmarks // -#include "spdlog/sinks/basic_file_sink.h" -#include "spdlog/sinks/daily_file_sink.h" -#include "spdlog/sinks/null_sink.h" -#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 @@ -24,6 +14,11 @@ #include #include +#include "spdlog/sinks/basic_file_sink.h" +#include "spdlog/sinks/daily_file_sink.h" +#include "spdlog/sinks/null_sink.h" +#include "spdlog/sinks/rotating_file_sink.h" +#include "spdlog/spdlog.h" #include "utils.h" void bench(int howmany, std::shared_ptr log); diff --git a/cmake/fmtlib.cmake b/cmake/fmtlib.cmake index a8443f0f..4c6833a2 100644 --- a/cmake/fmtlib.cmake +++ b/cmake/fmtlib.cmake @@ -1,15 +1,13 @@ include(FetchContent) FetchContent_Declare( - fmt - DOWNLOAD_EXTRACT_TIMESTAMP FALSE - URL https://github.com/fmtlib/fmt/archive/refs/tags/11.0.2.tar.gz - URL_HASH SHA256=6cb1e6d37bdcb756dbbe59be438790db409cdb4868c66e888d5df9f13f7c027f) + fmt DOWNLOAD_EXTRACT_TIMESTAMP FALSE URL https://github.com/fmtlib/fmt/archive/refs/tags/11.0.2.tar.gz + URL_HASH SHA256=6cb1e6d37bdcb756dbbe59be438790db409cdb4868c66e888d5df9f13f7c027f) FetchContent_GetProperties(fmt) if(NOT fmt_POPULATED) FetchContent_Populate(fmt) # We do not require os features of fmt set(FMT_OS OFF CACHE BOOL "Disable FMT_OS" FORCE) add_subdirectory(${fmt_SOURCE_DIR} ${fmt_BINARY_DIR}) - set_target_properties(fmt PROPERTIES FOLDER "third-party") -endif () + set_target_properties(fmt PROPERTIES FOLDER "third-party") +endif() 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/example/CMakeLists.txt b/example/CMakeLists.txt index b197afe1..90211423 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -9,4 +9,4 @@ if(NOT TARGET spdlog) endif() add_executable(example example.cpp) -target_link_libraries(example PRIVATE spdlog::spdlog $<$:ws2_32>) \ No newline at end of file +target_link_libraries(example PRIVATE spdlog::spdlog $<$:ws2_32>) diff --git a/example/example.cpp b/example/example.cpp index 2c63b896..31f4258b 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -161,8 +161,7 @@ void async_example() { // {:p} - don't print the position on each line start. // {: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; for (int i = 0; i < 80; i++) { @@ -177,26 +176,14 @@ void binary_example() { // logger->info("hexdump style: {:a}", spdlog::to_hex(buf)); // logger->info("hexdump style, 20 chars per line {:a}", spdlog::to_hex(buf, 20)); } -#else -void binary_example() { - // not supported with std::format yet -} -#endif // Log a vector of numbers -#ifndef SPDLOG_USE_STD_FORMAT - #include "fmt/ranges.h" +#include "fmt/ranges.h" void vector_example() { std::vector vec = {1, 2, 3}; spdlog::info("Vector example: {}", vec); } -#else -void vector_example() {} -#endif - -// ! DSPDLOG_USE_STD_FORMAT - // Compile time log levels. // define SPDLOG_ACTIVE_LEVEL to required level (e.g. SPDLOG_LEVEL_TRACE) void trace_example() { @@ -250,7 +237,6 @@ struct my_type { : i(i) {} }; -#ifndef SPDLOG_USE_STD_FORMAT // when using fmtlib template <> struct fmt::formatter : fmt::formatter { auto format(my_type my, format_context &ctx) const -> decltype(ctx.out()) { @@ -258,15 +244,6 @@ struct fmt::formatter : fmt::formatter { } }; -#else // when using std::format -template <> -struct std::formatter : std::formatter { - auto format(my_type my, format_context &ctx) const -> decltype(ctx.out()) { - return format_to(ctx.out(), "[my_type i={}]", my.i); - } -}; -#endif - void user_defined_example() { spdlog::info("user defined type: {}", my_type(14)); } // Custom error handler. Will be triggered on log failure. diff --git a/include/spdlog/common.h b/include/spdlog/common.h index a586bf7b..d076d455 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -21,10 +21,6 @@ #include #endif -#ifdef SPDLOG_USE_STD_FORMAT - #include -#endif - #if defined(SPDLOG_SHARED_LIB) #if defined(_WIN32) #ifdef spdlog_EXPORTS @@ -41,15 +37,10 @@ #include "fmt/fmt.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) - #define SPDLOG_FMT_STRING(format_string) FMT_STRING(format_string) - #if defined(SPDLOG_WCHAR_FILENAMES) - #include "fmt/xchar.h" - #endif -#else - #define SPDLOG_FMT_RUNTIME(format_string) format_string - #define SPDLOG_FMT_STRING(format_string) format_string +#define SPDLOG_FMT_RUNTIME(format_string) fmt::runtime(format_string) +#define SPDLOG_FMT_STRING(format_string) FMT_STRING(format_string) +#if defined(SPDLOG_WCHAR_FILENAMES) + #include "fmt/xchar.h" #endif #ifndef SPDLOG_FUNCTION @@ -98,29 +89,14 @@ using err_handler = std::function; using string_view_t = std::basic_string_view; using wstring_view_t = std::basic_string_view; -#ifdef SPDLOG_USE_STD_FORMAT -namespace fmt_lib = std; -using memory_buf_t = std::string; -using wmemory_buf_t = std::wstring; - -template - #if __cpp_lib_format >= 202207L - using format_string_t = std::format_string; - #else - using format_string_t = std::string_view; - #endif - - #define SPDLOG_BUF_TO_STRING(x) x -#else // use fmt lib instead of std::format namespace fmt_lib = fmt; - using memory_buf_t = fmt::basic_memory_buffer; +using wmemory_buf_t = fmt::basic_memory_buffer; + template using format_string_t = fmt::format_string; -using wmemory_buf_t = fmt::basic_memory_buffer; - #define SPDLOG_BUF_TO_STRING(x) fmt::to_string(x) -#endif // SPDLOG_USE_STD_FORMAT +#define SPDLOG_BUF_TO_STRING(x) fmt::to_string(x) #define SPDLOG_LEVEL_TRACE 0 #define SPDLOG_LEVEL_DEBUG 1 #define SPDLOG_LEVEL_INFO 2 @@ -231,27 +207,10 @@ namespace details { [[nodiscard]] constexpr spdlog::wstring_view_t to_string_view(spdlog::wstring_view_t str) noexcept { return str; } #endif -// convert format_string<...> to string_view depending on format lib versions -#if defined(SPDLOG_USE_STD_FORMAT) - #if __cpp_lib_format >= 202207L // std::format and __cpp_lib_format >= 202207L -template -[[nodiscard]] constexpr std::basic_string_view to_string_view(std::basic_format_string fmt) noexcept { - return fmt.get(); -} - #else // std::format and __cpp_lib_format < 202207L -template -[[nodiscard]] constexpr std::basic_string_view to_string_view(std::basic_format_string fmt) noexcept { - return fmt; -} - #endif -#else // {fmt} version - template [[nodiscard]] constexpr fmt::basic_string_view to_string_view(fmt::basic_format_string fmt) noexcept { return fmt; } -#endif - } // namespace details } // namespace spdlog diff --git a/include/spdlog/details/fmt_helper.h b/include/spdlog/details/fmt_helper.h index 5ee8bb14..ff10dcc3 100644 --- a/include/spdlog/details/fmt_helper.h +++ b/include/spdlog/details/fmt_helper.h @@ -9,11 +9,6 @@ #include "../common.h" #include "../fmt/fmt.h" -#ifdef SPDLOG_USE_STD_FORMAT - #include - #include -#endif - // Some fmt helpers to efficiently format and pad ints and strings namespace spdlog { namespace details { @@ -24,27 +19,11 @@ inline void append_string_view(spdlog::string_view_t view, memory_buf_t &dest) { dest.append(buf_ptr, buf_ptr + view.size()); } -#ifdef SPDLOG_USE_STD_FORMAT -template -inline void append_int(T n, memory_buf_t &dest) { - // Buffer should be large enough to hold all digits (digits10 + 1) and a sign - constexpr const auto BUF_SIZE = std::numeric_limits::digits10 + 2; - char buf[BUF_SIZE]; - - auto [ptr, ec] = std::to_chars(buf, buf + BUF_SIZE, n, 10); - if (ec == std::errc()) { - dest.append(buf, ptr); - } else { - throw_spdlog_ex("Failed to format int", static_cast(ec)); - } -} -#else template inline void append_int(T n, memory_buf_t &dest) { fmt::format_int i(n); dest.append(i.data(), i.data() + i.size()); } -#endif template constexpr unsigned int count_digits_fallback(T n) { @@ -66,19 +45,16 @@ constexpr unsigned int count_digits_fallback(T n) { template inline unsigned int count_digits(T n) { using count_type = typename std::conditional<(sizeof(T) > sizeof(uint32_t)), uint64_t, uint32_t>::type; -#ifdef SPDLOG_USE_STD_FORMAT - return count_digits_fallback(static_cast(n)); -#else + return static_cast(fmt:: - // fmt 7.0.0 renamed the internal namespace to detail. - // See: https://github.com/fmtlib/fmt/issues/1538 - #if FMT_VERSION < 70000 +// fmt 7.0.0 renamed the internal namespace to detail. +// See: https://github.com/fmtlib/fmt/issues/1538 +#if FMT_VERSION < 70000 internal - #else +#else detail - #endif - ::count_digits(static_cast(n))); #endif + ::count_digits(static_cast(n))); } inline void pad2(int n, memory_buf_t &dest) { diff --git a/include/spdlog/fmt/bin_to_hex.h b/include/spdlog/fmt/bin_to_hex.h index 71ebe26a..ae3c1588 100644 --- a/include/spdlog/fmt/bin_to_hex.h +++ b/include/spdlog/fmt/bin_to_hex.h @@ -88,13 +88,7 @@ inline details::dump_info to_hex(const It range_begin, const It range_end, s } // namespace spdlog -namespace -#ifdef SPDLOG_USE_STD_FORMAT - std -#else - fmt -#endif -{ +namespace fmt { template struct formatter, char> { @@ -142,13 +136,7 @@ struct formatter, char> { constexpr const char *hex_upper = "0123456789ABCDEF"; constexpr const char *hex_lower = "0123456789abcdef"; const char *hex_chars = use_uppercase ? hex_upper : hex_lower; - -#if !defined(SPDLOG_USE_STD_FORMAT) && FMT_VERSION < 60000 - auto inserter = ctx.begin(); -#else auto inserter = ctx.out(); -#endif - int size_per_line = static_cast(the_range.size_per_line()); auto start_of_line = the_range.get_begin(); for (auto i = the_range.get_begin(); i != the_range.get_end(); i++) { @@ -215,4 +203,4 @@ struct formatter, char> { } } }; -} // namespace std +} // namespace fmt diff --git a/include/spdlog/fmt/fmt.h b/include/spdlog/fmt/fmt.h index e631e6bb..af6f5203 100644 --- a/include/spdlog/fmt/fmt.h +++ b/include/spdlog/fmt/fmt.h @@ -5,14 +5,5 @@ #pragma once -// -// Include a bundled header-only copy of fmtlib or an external one. -// By default, spdlog include its own copy. -// #include "../spdlog_config.h" - -#if defined(SPDLOG_USE_STD_FORMAT) // use std::format - #include -#else - #include "fmt/format.h" -#endif +#include "fmt/format.h" diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index 416de65e..7a2bd52d 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -187,14 +187,9 @@ protected: void log_with_format_(source_loc loc, level lvl, const format_string_t &fmt, Args &&...args) { assert(should_log(lvl)); SPDLOG_TRY { -#ifdef SPDLOG_USE_STD_FORMAT - auto formatted = std::vformat(fmt, std::make_format_args(args...)); - sink_it_(details::log_msg(loc, name_, lvl, formatted)); -#else // use {fmt} lib memory_buf_t buf; fmt::vformat_to(std::back_inserter(buf), fmt, fmt::make_format_args(args...)); sink_it_(details::log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size()))); -#endif } SPDLOG_LOGGER_CATCH(loc) } diff --git a/include/spdlog/stopwatch.h b/include/spdlog/stopwatch.h index ea9182e8..f101749e 100644 --- a/include/spdlog/stopwatch.h +++ b/include/spdlog/stopwatch.h @@ -51,13 +51,7 @@ public: } // namespace spdlog // Support for fmt formatting (e.g. "{:012.9}" or just "{}") -namespace -#ifdef SPDLOG_USE_STD_FORMAT - std -#else - fmt -#endif -{ +namespace fmt { template <> struct formatter : formatter { @@ -66,4 +60,4 @@ struct formatter : formatter { return formatter::format(sw.elapsed().count(), ctx); } }; -} // namespace std +} // namespace fmt 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..a963fc72 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -19,12 +19,12 @@ if(Catch2_FOUND) else() message(STATUS "Bundled version of Catch will be downloaded and used.") include(FetchContent) - FetchContent_Declare(Catch2 - GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG 53d0d913a422d356b23dd927547febdf69ee9081 # v3.5.0 + FetchContent_Declare( + Catch2 GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG 53d0d913a422d356b23dd927547febdf69ee9081 # v3.5.0 ) FetchContent_MakeAvailable(Catch2) - set_target_properties(Catch2 Catch2WithMain PROPERTIES FOLDER "third-party") + set_target_properties(Catch2 Catch2WithMain PROPERTIES FOLDER "third-party") endif() set(SPDLOG_UTESTS_SOURCES @@ -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) @@ -82,9 +79,9 @@ function(spdlog_prepare_test test_target spdlog_lib) target_link_libraries(${test_target} PRIVATE Catch2::Catch2WithMain) if(SPDLOG_SANITIZE_ADDRESS) spdlog_enable_addr_sanitizer(${test_target}) - elseif (SPDLOG_SANITIZE_THREAD) + elseif(SPDLOG_SANITIZE_THREAD) spdlog_enable_thread_sanitizer(${test_target}) - endif () + endif() add_test(NAME ${test_target} COMMAND ${test_target}) set_tests_properties(${test_target} PROPERTIES RUN_SERIAL ON) endfunction() diff --git a/tests/test_create_dir.cpp b/tests/test_create_dir.cpp index 6f38006c..7d46dfc0 100644 --- a/tests/test_create_dir.cpp +++ b/tests/test_create_dir.cpp @@ -81,8 +81,7 @@ TEST_CASE("dir_name", "[create_dir]") { // clang-format off #include #include - // clang-format on - +// clang-format on std::string get_full_path(const std::string &relative_folder_path) { char full_path[MAX_PATH]; 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..25d0f335 100644 --- a/tests/test_errors.cpp +++ b/tests/test_errors.cpp @@ -18,7 +18,6 @@ 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 +44,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 +59,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 +83,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]") {