mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-26 18:41:35 +08:00
V2.x no std format (#3271)
Some checks are pending
linux / ${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }}) (map[asan:ON build_type:Debug … (push) Waiting to run
linux / ${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }}) (map[build_type:Debug compiler… (push) Waiting to run
linux / ${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }}) (map[build_type:Release compil… (push) Waiting to run
macos / macOS Clang (C++17, Release) (push) Waiting to run
windows / build (map[BUILD_EXAMPLE:OFF BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:20 FATAL_ERRORS:ON GENERATOR:Visual Studio 17 2022 USE_STD_FORMAT:ON WCHAR:OFF WCHAR_FILES:OFF]) (push) Waiting to run
windows / build (map[BUILD_EXAMPLE:OFF BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:20 FATAL_ERRORS:ON GENERATOR:Visual Studio 17 2022 USE_STD_FORMAT:ON WCHAR:ON WCHAR_FILES:ON]) (push) Waiting to run
windows / build (map[BUILD_EXAMPLE:ON BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:17 FATAL_ERRORS:ON GENERATOR:Visual Studio 17 2022 USE_STD_FORMAT:OFF WCHAR:OFF WCHAR_FILES:OFF]) (push) Waiting to run
windows / build_2019 (map[BUILD_EXAMPLE:ON BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:17 FATAL_ERRORS:ON GENERATOR:Visual Studio 16 2019 USE_STD_FORMAT:OFF WCHAR:OFF WCHAR_FILES:OFF]) (push) Waiting to run
windows / build_2019 (map[BUILD_EXAMPLE:ON BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:20 FATAL_ERRORS:ON GENERATOR:Visual Studio 16 2019 USE_STD_FORMAT:OFF WCHAR:OFF WCHAR_FILES:OFF]) (push) Waiting to run
Some checks are pending
linux / ${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }}) (map[asan:ON build_type:Debug … (push) Waiting to run
linux / ${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }}) (map[build_type:Debug compiler… (push) Waiting to run
linux / ${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }}) (map[build_type:Release compil… (push) Waiting to run
macos / macOS Clang (C++17, Release) (push) Waiting to run
windows / build (map[BUILD_EXAMPLE:OFF BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:20 FATAL_ERRORS:ON GENERATOR:Visual Studio 17 2022 USE_STD_FORMAT:ON WCHAR:OFF WCHAR_FILES:OFF]) (push) Waiting to run
windows / build (map[BUILD_EXAMPLE:OFF BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:20 FATAL_ERRORS:ON GENERATOR:Visual Studio 17 2022 USE_STD_FORMAT:ON WCHAR:ON WCHAR_FILES:ON]) (push) Waiting to run
windows / build (map[BUILD_EXAMPLE:ON BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:17 FATAL_ERRORS:ON GENERATOR:Visual Studio 17 2022 USE_STD_FORMAT:OFF WCHAR:OFF WCHAR_FILES:OFF]) (push) Waiting to run
windows / build_2019 (map[BUILD_EXAMPLE:ON BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:17 FATAL_ERRORS:ON GENERATOR:Visual Studio 16 2019 USE_STD_FORMAT:OFF WCHAR:OFF WCHAR_FILES:OFF]) (push) Waiting to run
windows / build_2019 (map[BUILD_EXAMPLE:ON BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:20 FATAL_ERRORS:ON GENERATOR:Visual Studio 16 2019 USE_STD_FORMAT:OFF WCHAR:OFF WCHAR_FILES:OFF]) (push) Waiting to run
* Removed SPDLOG_USE_STD_FORMAT * Removed SPDLOG_USE_STD_FORMAT * clang-format * Fix windows.yml ci * Fix ci
This commit is contained in:
parent
9fea0e5fa8
commit
63535f140b
22
.github/workflows/linux.yml
vendored
22
.github/workflows/linux.yml
vendored
@ -59,25 +59,3 @@ jobs:
|
|||||||
-DSPDLOG_SANITIZE_THREAD=${{ matrix.config.tsan || 'OFF' }}
|
-DSPDLOG_SANITIZE_THREAD=${{ matrix.config.tsan || 'OFF' }}
|
||||||
make -j 4
|
make -j 4
|
||||||
ctest -j 4 --output-on-failure
|
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
|
|
||||||
|
2
.github/workflows/windows.yml
vendored
2
.github/workflows/windows.yml
vendored
@ -57,7 +57,6 @@ jobs:
|
|||||||
-D SPDLOG_BUILD_EXAMPLE=${{ matrix.config.BUILD_EXAMPLE }} `
|
-D SPDLOG_BUILD_EXAMPLE=${{ matrix.config.BUILD_EXAMPLE }} `
|
||||||
-D SPDLOG_BUILD_TESTS=ON `
|
-D SPDLOG_BUILD_TESTS=ON `
|
||||||
-D SPDLOG_BUILD_WARNINGS=${{ matrix.config.FATAL_ERRORS }} `
|
-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 }} ..
|
-D CMAKE_CXX_STANDARD=${{ matrix.config.CXX_STANDARD }} ..
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
@ -118,7 +117,6 @@ jobs:
|
|||||||
-D SPDLOG_BUILD_EXAMPLE=${{ matrix.config.BUILD_EXAMPLE }} `
|
-D SPDLOG_BUILD_EXAMPLE=${{ matrix.config.BUILD_EXAMPLE }} `
|
||||||
-D SPDLOG_BUILD_TESTS=ON `
|
-D SPDLOG_BUILD_TESTS=ON `
|
||||||
-D SPDLOG_BUILD_WARNINGS=${{ matrix.config.FATAL_ERRORS }} `
|
-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 }} ..
|
-D CMAKE_CXX_STANDARD=${{ matrix.config.CXX_STANDARD }} ..
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
|
@ -34,7 +34,6 @@ elseif(CMAKE_CXX_STANDARD LESS 17)
|
|||||||
endif()
|
endif()
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
|
||||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
|
||||||
if(CMAKE_SYSTEM_NAME MATCHES "CYGWIN" OR CMAKE_SYSTEM_NAME MATCHES "MSYS" OR CMAKE_SYSTEM_NAME MATCHES "MINGW")
|
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
|
# build shared option
|
||||||
option(SPDLOG_BUILD_SHARED "Build shared library" OFF)
|
option(SPDLOG_BUILD_SHARED "Build shared library" OFF)
|
||||||
|
|
||||||
|
|
||||||
# example options
|
# example options
|
||||||
option(SPDLOG_BUILD_EXAMPLE "Build example" ${SPDLOG_MASTER_PROJECT})
|
option(SPDLOG_BUILD_EXAMPLE "Build example" ${SPDLOG_MASTER_PROJECT})
|
||||||
|
|
||||||
@ -77,19 +75,9 @@ option(SPDLOG_BUILD_WARNINGS "Enable compiler warnings" OFF)
|
|||||||
# install options
|
# install options
|
||||||
option(SPDLOG_SYSTEM_INCLUDES "Include as system headers (skip for clang-tidy)." OFF)
|
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_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_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)
|
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
|
# misc tweakme options
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
option(SPDLOG_WCHAR_FILENAMES "Support wchar filenames" OFF)
|
option(SPDLOG_WCHAR_FILENAMES "Support wchar filenames" OFF)
|
||||||
@ -126,35 +114,31 @@ if(SPDLOG_BUILD_SHARED)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||||
# place dlls and libs and executables in the same directory
|
# place dlls and libs and executables in the same directory
|
||||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>)
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>)
|
||||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>)
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>)
|
||||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>)
|
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>)
|
||||||
set(CMAKE_PDB_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>)
|
set(CMAKE_PDB_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>)
|
||||||
|
|
||||||
# make sure __cplusplus is defined
|
# make sure __cplusplus is defined
|
||||||
add_compile_options(/Zc:__cplusplus)
|
add_compile_options(/Zc:__cplusplus)
|
||||||
# enable parallel build for the solution
|
# enable parallel build for the solution
|
||||||
add_compile_options(/MP)
|
add_compile_options(/MP)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
message(STATUS "spdlog version: ${SPDLOG_VERSION}")
|
message(STATUS "spdlog version: ${SPDLOG_VERSION}")
|
||||||
message(STATUS "spdlog build type: " ${CMAKE_BUILD_TYPE})
|
message(STATUS "spdlog build type: " ${CMAKE_BUILD_TYPE})
|
||||||
message(STATUS "spdlog build shared: " ${BUILD_SHARED_LIBS})
|
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})
|
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)
|
||||||
if (SPDLOG_FMT_EXTERNAL)
|
find_package(fmt REQUIRED)
|
||||||
find_package(fmt REQUIRED)
|
message(STATUS "Using external fmt lib version: ${fmt_VERSION}")
|
||||||
message(STATUS "Using external fmt lib version: ${fmt_VERSION}")
|
else()
|
||||||
else()
|
include(cmake/fmtlib.cmake)
|
||||||
include(cmake/fmtlib.cmake)
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
@ -217,8 +201,7 @@ set(SPDLOG_HEADERS
|
|||||||
"include/spdlog/sinks/syslog_sink.h"
|
"include/spdlog/sinks/syslog_sink.h"
|
||||||
"include/spdlog/sinks/systemd_sink.h"
|
"include/spdlog/sinks/systemd_sink.h"
|
||||||
"include/spdlog/sinks/tcp_sink.h"
|
"include/spdlog/sinks/tcp_sink.h"
|
||||||
"include/spdlog/sinks/udp_sink.h"
|
"include/spdlog/sinks/udp_sink.h")
|
||||||
)
|
|
||||||
|
|
||||||
set(SPDLOG_SRCS
|
set(SPDLOG_SRCS
|
||||||
"src/async_logger.cpp"
|
"src/async_logger.cpp"
|
||||||
@ -242,20 +225,18 @@ set(SPDLOG_SRCS
|
|||||||
"src/sinks/stdout_sinks.cpp")
|
"src/sinks/stdout_sinks.cpp")
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
list(APPEND SPDLOG_SRCS
|
list(APPEND SPDLOG_SRCS "src/details/os_windows.cpp" "src/sinks/wincolor_sink.cpp")
|
||||||
"src/details/os_windows.cpp"
|
list(
|
||||||
"src/sinks/wincolor_sink.cpp")
|
APPEND
|
||||||
list(APPEND SPDLOG_HEADERS
|
SPDLOG_HEADERS
|
||||||
"include/spdlog/details/tcp_client_windows.h"
|
"include/spdlog/details/tcp_client_windows.h"
|
||||||
"include/spdlog/details/udp_client_windows.h"
|
"include/spdlog/details/udp_client_windows.h"
|
||||||
"include/spdlog/details/windows_include.h"
|
"include/spdlog/details/windows_include.h"
|
||||||
"include/spdlog/sinks/win_eventlog_sink.h"
|
"include/spdlog/sinks/win_eventlog_sink.h"
|
||||||
"include/spdlog/sinks/wincolor_sink.h")
|
"include/spdlog/sinks/wincolor_sink.h")
|
||||||
else()
|
else()
|
||||||
list(APPEND SPDLOG_SRCS "src/details/os_unix.cpp")
|
list(APPEND SPDLOG_SRCS "src/details/os_unix.cpp")
|
||||||
list(APPEND SPDLOG_HEADERS
|
list(APPEND SPDLOG_HEADERS "include/spdlog/details/tcp_client_unix.h" "include/spdlog/details/udp_client_unix.h")
|
||||||
"include/spdlog/details/tcp_client_unix.h"
|
|
||||||
"include/spdlog/details/udp_client_unix.h")
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Generate spdlog_config.h based on the current configuration
|
# Generate spdlog_config.h based on the current configuration
|
||||||
@ -287,16 +268,14 @@ endif()
|
|||||||
|
|
||||||
set_target_properties(spdlog PROPERTIES PUBLIC_HEADER "${SPDLOG_HEADERS}")
|
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 "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
|
||||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
|
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
|
||||||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
|
|
||||||
|
|
||||||
target_link_libraries(spdlog PUBLIC Threads::Threads)
|
target_link_libraries(spdlog PUBLIC Threads::Threads)
|
||||||
if(NOT SPDLOG_USE_STD_FORMAT)
|
target_link_libraries(spdlog PUBLIC fmt::fmt)
|
||||||
target_link_libraries(spdlog PUBLIC fmt::fmt)
|
|
||||||
endif()
|
|
||||||
spdlog_enable_warnings(spdlog)
|
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_target_properties(spdlog PROPERTIES DEBUG_POSTFIX d)
|
||||||
|
|
||||||
# set source groups for visual studio
|
# set source groups for visual studio
|
||||||
@ -313,7 +292,6 @@ if(ANDROID)
|
|||||||
target_link_libraries(spdlog PUBLIC log)
|
target_link_libraries(spdlog PUBLIC log)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
# If exceptions are disabled, disable them in the bundled fmt as well
|
# If exceptions are disabled, disable them in the bundled fmt as well
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
@ -403,8 +381,7 @@ if(SPDLOG_INSTALL)
|
|||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
include(cmake/spdlogCPack.cmake)
|
include(cmake/spdlogCPack.cmake)
|
||||||
|
|
||||||
# Install spdlog_config.h file
|
# Install spdlog_config.h file Assume your tweakme.h.in is located in the same directory as CMakeLists.txt
|
||||||
# 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_IN "${CMAKE_CURRENT_SOURCE_DIR}/tweakme.h.in")
|
||||||
set(TWEAKME_OUT "${CMAKE_CURRENT_BINARY_DIR}/include/spdlog/tweakme.h")
|
set(TWEAKME_OUT "${CMAKE_CURRENT_BINARY_DIR}/include/spdlog/tweakme.h")
|
||||||
endif()
|
endif()
|
||||||
|
@ -22,7 +22,7 @@ if(NOT benchmark_FOUND)
|
|||||||
# Do not build and run googlebenchmark tests
|
# Do not build and run googlebenchmark tests
|
||||||
FetchContent_Declare(googlebenchmark GIT_REPOSITORY https://github.com/google/benchmark.git GIT_TAG v1.6.0)
|
FetchContent_Declare(googlebenchmark GIT_REPOSITORY https://github.com/google/benchmark.git GIT_TAG v1.6.0)
|
||||||
FetchContent_MakeAvailable(googlebenchmark)
|
FetchContent_MakeAvailable(googlebenchmark)
|
||||||
set_target_properties(benchmark PROPERTIES FOLDER "third-party")
|
set_target_properties(benchmark PROPERTIES FOLDER "third-party")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_executable(bench bench.cpp)
|
add_executable(bench bench.cpp)
|
||||||
|
@ -6,17 +6,7 @@
|
|||||||
//
|
//
|
||||||
// bench.cpp : spdlog benchmarks
|
// bench.cpp : spdlog benchmarks
|
||||||
//
|
//
|
||||||
#include "spdlog/sinks/basic_file_sink.h"
|
#include <fmt/format.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 <format>
|
|
||||||
#else
|
|
||||||
#include <fmt/format.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <cstdlib> // EXIT_FAILURE
|
#include <cstdlib> // EXIT_FAILURE
|
||||||
@ -24,6 +14,11 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
|
#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"
|
#include "utils.h"
|
||||||
|
|
||||||
void bench(int howmany, std::shared_ptr<spdlog::logger> log);
|
void bench(int howmany, std::shared_ptr<spdlog::logger> log);
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
|
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
fmt
|
fmt DOWNLOAD_EXTRACT_TIMESTAMP FALSE URL https://github.com/fmtlib/fmt/archive/refs/tags/11.0.2.tar.gz
|
||||||
DOWNLOAD_EXTRACT_TIMESTAMP FALSE
|
URL_HASH SHA256=6cb1e6d37bdcb756dbbe59be438790db409cdb4868c66e888d5df9f13f7c027f)
|
||||||
URL https://github.com/fmtlib/fmt/archive/refs/tags/11.0.2.tar.gz
|
|
||||||
URL_HASH SHA256=6cb1e6d37bdcb756dbbe59be438790db409cdb4868c66e888d5df9f13f7c027f)
|
|
||||||
FetchContent_GetProperties(fmt)
|
FetchContent_GetProperties(fmt)
|
||||||
if(NOT fmt_POPULATED)
|
if(NOT fmt_POPULATED)
|
||||||
FetchContent_Populate(fmt)
|
FetchContent_Populate(fmt)
|
||||||
# We do not require os features of fmt
|
# We do not require os features of fmt
|
||||||
set(FMT_OS OFF CACHE BOOL "Disable FMT_OS" FORCE)
|
set(FMT_OS OFF CACHE BOOL "Disable FMT_OS" FORCE)
|
||||||
add_subdirectory(${fmt_SOURCE_DIR} ${fmt_BINARY_DIR})
|
add_subdirectory(${fmt_SOURCE_DIR} ${fmt_BINARY_DIR})
|
||||||
set_target_properties(fmt PROPERTIES FOLDER "third-party")
|
set_target_properties(fmt PROPERTIES FOLDER "third-party")
|
||||||
endif ()
|
endif()
|
||||||
|
@ -7,10 +7,7 @@ include(CMakeFindDependencyMacro)
|
|||||||
|
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
|
|
||||||
set(SPDLOG_USE_STD_FORMAT @SPDLOG_USE_STD_FORMAT@)
|
find_dependency(fmt CONFIG)
|
||||||
if(NOT SPDLOG_USE_STD_FORMAT)
|
|
||||||
find_dependency(fmt CONFIG)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(config_targets_file @config_targets_file@)
|
set(config_targets_file @config_targets_file@)
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/${config_targets_file}")
|
include("${CMAKE_CURRENT_LIST_DIR}/${config_targets_file}")
|
||||||
|
@ -27,9 +27,5 @@
|
|||||||
// Disable default logger creation
|
// Disable default logger creation
|
||||||
#cmakedefine SPDLOG_DISABLE_DEFAULT_LOGGER
|
#cmakedefine SPDLOG_DISABLE_DEFAULT_LOGGER
|
||||||
|
|
||||||
// Use std::format instead of fmtlib
|
|
||||||
#cmakedefine SPDLOG_USE_STD_FORMAT
|
|
||||||
|
|
||||||
// Use external fmtlib instead of bundled
|
// Use external fmtlib instead of bundled
|
||||||
#cmakedefine SPDLOG_FMT_EXTERNAL
|
#cmakedefine SPDLOG_FMT_EXTERNAL
|
||||||
|
|
||||||
|
@ -161,8 +161,7 @@ void async_example() {
|
|||||||
// {:p} - don't print the position on each line start.
|
// {:p} - don't print the position on each line start.
|
||||||
// {:n} - don't split the output to lines.
|
// {: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() {
|
void binary_example() {
|
||||||
std::vector<char> buf;
|
std::vector<char> buf;
|
||||||
for (int i = 0; i < 80; i++) {
|
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: {:a}", spdlog::to_hex(buf));
|
||||||
// logger->info("hexdump style, 20 chars per line {:a}", spdlog::to_hex(buf, 20));
|
// 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
|
// Log a vector of numbers
|
||||||
#ifndef SPDLOG_USE_STD_FORMAT
|
#include "fmt/ranges.h"
|
||||||
#include "fmt/ranges.h"
|
|
||||||
void vector_example() {
|
void vector_example() {
|
||||||
std::vector<int> vec = {1, 2, 3};
|
std::vector<int> vec = {1, 2, 3};
|
||||||
spdlog::info("Vector example: {}", vec);
|
spdlog::info("Vector example: {}", vec);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
void vector_example() {}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// ! DSPDLOG_USE_STD_FORMAT
|
|
||||||
|
|
||||||
// Compile time log levels.
|
// Compile time log levels.
|
||||||
// define SPDLOG_ACTIVE_LEVEL to required level (e.g. SPDLOG_LEVEL_TRACE)
|
// define SPDLOG_ACTIVE_LEVEL to required level (e.g. SPDLOG_LEVEL_TRACE)
|
||||||
void trace_example() {
|
void trace_example() {
|
||||||
@ -250,7 +237,6 @@ struct my_type {
|
|||||||
: i(i) {}
|
: i(i) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef SPDLOG_USE_STD_FORMAT // when using fmtlib
|
|
||||||
template <>
|
template <>
|
||||||
struct fmt::formatter<my_type> : fmt::formatter<std::string> {
|
struct fmt::formatter<my_type> : fmt::formatter<std::string> {
|
||||||
auto format(my_type my, format_context &ctx) const -> decltype(ctx.out()) {
|
auto format(my_type my, format_context &ctx) const -> decltype(ctx.out()) {
|
||||||
@ -258,15 +244,6 @@ struct fmt::formatter<my_type> : fmt::formatter<std::string> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#else // when using std::format
|
|
||||||
template <>
|
|
||||||
struct std::formatter<my_type> : std::formatter<std::string> {
|
|
||||||
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)); }
|
void user_defined_example() { spdlog::info("user defined type: {}", my_type(14)); }
|
||||||
|
|
||||||
// Custom error handler. Will be triggered on log failure.
|
// Custom error handler. Will be triggered on log failure.
|
||||||
|
@ -21,10 +21,6 @@
|
|||||||
#include <version>
|
#include <version>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SPDLOG_USE_STD_FORMAT
|
|
||||||
#include <format>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(SPDLOG_SHARED_LIB)
|
#if defined(SPDLOG_SHARED_LIB)
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#ifdef spdlog_EXPORTS
|
#ifdef spdlog_EXPORTS
|
||||||
@ -41,15 +37,10 @@
|
|||||||
|
|
||||||
#include "fmt/fmt.h"
|
#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_RUNTIME(format_string) fmt::runtime(format_string)
|
#define SPDLOG_FMT_STRING(format_string) FMT_STRING(format_string)
|
||||||
#define SPDLOG_FMT_STRING(format_string) FMT_STRING(format_string)
|
#if defined(SPDLOG_WCHAR_FILENAMES)
|
||||||
#if defined(SPDLOG_WCHAR_FILENAMES)
|
#include "fmt/xchar.h"
|
||||||
#include "fmt/xchar.h"
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#define SPDLOG_FMT_RUNTIME(format_string) format_string
|
|
||||||
#define SPDLOG_FMT_STRING(format_string) format_string
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef SPDLOG_FUNCTION
|
#ifndef SPDLOG_FUNCTION
|
||||||
@ -98,29 +89,14 @@ using err_handler = std::function<void(const std::string &err_msg)>;
|
|||||||
using string_view_t = std::basic_string_view<char>;
|
using string_view_t = std::basic_string_view<char>;
|
||||||
using wstring_view_t = std::basic_string_view<wchar_t>;
|
using wstring_view_t = std::basic_string_view<wchar_t>;
|
||||||
|
|
||||||
#ifdef SPDLOG_USE_STD_FORMAT
|
|
||||||
namespace fmt_lib = std;
|
|
||||||
using memory_buf_t = std::string;
|
|
||||||
using wmemory_buf_t = std::wstring;
|
|
||||||
|
|
||||||
template <typename... Args>
|
|
||||||
#if __cpp_lib_format >= 202207L
|
|
||||||
using format_string_t = std::format_string<Args...>;
|
|
||||||
#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;
|
namespace fmt_lib = fmt;
|
||||||
|
|
||||||
using memory_buf_t = fmt::basic_memory_buffer<char, 250>;
|
using memory_buf_t = fmt::basic_memory_buffer<char, 250>;
|
||||||
|
using wmemory_buf_t = fmt::basic_memory_buffer<wchar_t, 250>;
|
||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
using format_string_t = fmt::format_string<Args...>;
|
using format_string_t = fmt::format_string<Args...>;
|
||||||
using wmemory_buf_t = fmt::basic_memory_buffer<wchar_t, 250>;
|
|
||||||
#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_TRACE 0
|
||||||
#define SPDLOG_LEVEL_DEBUG 1
|
#define SPDLOG_LEVEL_DEBUG 1
|
||||||
#define SPDLOG_LEVEL_INFO 2
|
#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; }
|
[[nodiscard]] constexpr spdlog::wstring_view_t to_string_view(spdlog::wstring_view_t str) noexcept { return str; }
|
||||||
#endif
|
#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 <typename T, typename... Args>
|
|
||||||
[[nodiscard]] constexpr std::basic_string_view<T> to_string_view(std::basic_format_string<T, Args...> fmt) noexcept {
|
|
||||||
return fmt.get();
|
|
||||||
}
|
|
||||||
#else // std::format and __cpp_lib_format < 202207L
|
|
||||||
template <typename T, typename... Args>
|
|
||||||
[[nodiscard]] constexpr std::basic_string_view<T> to_string_view(std::basic_format_string<T, Args...> fmt) noexcept {
|
|
||||||
return fmt;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#else // {fmt} version
|
|
||||||
|
|
||||||
template <typename T, typename... Args>
|
template <typename T, typename... Args>
|
||||||
[[nodiscard]] constexpr fmt::basic_string_view<T> to_string_view(fmt::basic_format_string<T, Args...> fmt) noexcept {
|
[[nodiscard]] constexpr fmt::basic_string_view<T> to_string_view(fmt::basic_format_string<T, Args...> fmt) noexcept {
|
||||||
return fmt;
|
return fmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} // namespace details
|
} // namespace details
|
||||||
} // namespace spdlog
|
} // namespace spdlog
|
||||||
|
@ -9,11 +9,6 @@
|
|||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
#include "../fmt/fmt.h"
|
#include "../fmt/fmt.h"
|
||||||
|
|
||||||
#ifdef SPDLOG_USE_STD_FORMAT
|
|
||||||
#include <charconv>
|
|
||||||
#include <limits>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Some fmt helpers to efficiently format and pad ints and strings
|
// Some fmt helpers to efficiently format and pad ints and strings
|
||||||
namespace spdlog {
|
namespace spdlog {
|
||||||
namespace details {
|
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());
|
dest.append(buf_ptr, buf_ptr + view.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SPDLOG_USE_STD_FORMAT
|
|
||||||
template <typename T>
|
|
||||||
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<T>::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<int>(ec));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline void append_int(T n, memory_buf_t &dest) {
|
inline void append_int(T n, memory_buf_t &dest) {
|
||||||
fmt::format_int i(n);
|
fmt::format_int i(n);
|
||||||
dest.append(i.data(), i.data() + i.size());
|
dest.append(i.data(), i.data() + i.size());
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr unsigned int count_digits_fallback(T n) {
|
constexpr unsigned int count_digits_fallback(T n) {
|
||||||
@ -66,19 +45,16 @@ constexpr unsigned int count_digits_fallback(T n) {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
inline unsigned int count_digits(T n) {
|
inline unsigned int count_digits(T n) {
|
||||||
using count_type = typename std::conditional<(sizeof(T) > sizeof(uint32_t)), uint64_t, uint32_t>::type;
|
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<count_type>(n));
|
|
||||||
#else
|
|
||||||
return static_cast<unsigned int>(fmt::
|
return static_cast<unsigned int>(fmt::
|
||||||
// fmt 7.0.0 renamed the internal namespace to detail.
|
// fmt 7.0.0 renamed the internal namespace to detail.
|
||||||
// See: https://github.com/fmtlib/fmt/issues/1538
|
// See: https://github.com/fmtlib/fmt/issues/1538
|
||||||
#if FMT_VERSION < 70000
|
#if FMT_VERSION < 70000
|
||||||
internal
|
internal
|
||||||
#else
|
#else
|
||||||
detail
|
detail
|
||||||
#endif
|
|
||||||
::count_digits(static_cast<count_type>(n)));
|
|
||||||
#endif
|
#endif
|
||||||
|
::count_digits(static_cast<count_type>(n)));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void pad2(int n, memory_buf_t &dest) {
|
inline void pad2(int n, memory_buf_t &dest) {
|
||||||
|
@ -88,13 +88,7 @@ inline details::dump_info<It> to_hex(const It range_begin, const It range_end, s
|
|||||||
|
|
||||||
} // namespace spdlog
|
} // namespace spdlog
|
||||||
|
|
||||||
namespace
|
namespace fmt {
|
||||||
#ifdef SPDLOG_USE_STD_FORMAT
|
|
||||||
std
|
|
||||||
#else
|
|
||||||
fmt
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct formatter<spdlog::details::dump_info<T>, char> {
|
struct formatter<spdlog::details::dump_info<T>, char> {
|
||||||
@ -142,13 +136,7 @@ struct formatter<spdlog::details::dump_info<T>, char> {
|
|||||||
constexpr const char *hex_upper = "0123456789ABCDEF";
|
constexpr const char *hex_upper = "0123456789ABCDEF";
|
||||||
constexpr const char *hex_lower = "0123456789abcdef";
|
constexpr const char *hex_lower = "0123456789abcdef";
|
||||||
const char *hex_chars = use_uppercase ? hex_upper : hex_lower;
|
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();
|
auto inserter = ctx.out();
|
||||||
#endif
|
|
||||||
|
|
||||||
int size_per_line = static_cast<int>(the_range.size_per_line());
|
int size_per_line = static_cast<int>(the_range.size_per_line());
|
||||||
auto start_of_line = the_range.get_begin();
|
auto start_of_line = the_range.get_begin();
|
||||||
for (auto i = the_range.get_begin(); i != the_range.get_end(); i++) {
|
for (auto i = the_range.get_begin(); i != the_range.get_end(); i++) {
|
||||||
@ -215,4 +203,4 @@ struct formatter<spdlog::details::dump_info<T>, char> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace std
|
} // namespace fmt
|
||||||
|
@ -5,14 +5,5 @@
|
|||||||
|
|
||||||
#pragma once
|
#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"
|
#include "../spdlog_config.h"
|
||||||
|
#include "fmt/format.h"
|
||||||
#if defined(SPDLOG_USE_STD_FORMAT) // use std::format
|
|
||||||
#include <format>
|
|
||||||
#else
|
|
||||||
#include "fmt/format.h"
|
|
||||||
#endif
|
|
||||||
|
@ -187,14 +187,9 @@ protected:
|
|||||||
void log_with_format_(source_loc loc, level lvl, const format_string_t<Args...> &fmt, Args &&...args) {
|
void log_with_format_(source_loc loc, level lvl, const format_string_t<Args...> &fmt, Args &&...args) {
|
||||||
assert(should_log(lvl));
|
assert(should_log(lvl));
|
||||||
SPDLOG_TRY {
|
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;
|
memory_buf_t buf;
|
||||||
fmt::vformat_to(std::back_inserter(buf), fmt, fmt::make_format_args(args...));
|
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())));
|
sink_it_(details::log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size())));
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
SPDLOG_LOGGER_CATCH(loc)
|
SPDLOG_LOGGER_CATCH(loc)
|
||||||
}
|
}
|
||||||
|
@ -51,13 +51,7 @@ public:
|
|||||||
} // namespace spdlog
|
} // namespace spdlog
|
||||||
|
|
||||||
// Support for fmt formatting (e.g. "{:012.9}" or just "{}")
|
// Support for fmt formatting (e.g. "{:012.9}" or just "{}")
|
||||||
namespace
|
namespace fmt {
|
||||||
#ifdef SPDLOG_USE_STD_FORMAT
|
|
||||||
std
|
|
||||||
#else
|
|
||||||
fmt
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct formatter<spdlog::stopwatch> : formatter<double> {
|
struct formatter<spdlog::stopwatch> : formatter<double> {
|
||||||
@ -66,4 +60,4 @@ struct formatter<spdlog::stopwatch> : formatter<double> {
|
|||||||
return formatter<double>::format(sw.elapsed().count(), ctx);
|
return formatter<double>::format(sw.elapsed().count(), ctx);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace std
|
} // namespace fmt
|
||||||
|
@ -26,13 +26,9 @@ spdlog_ex::spdlog_ex(std::string msg)
|
|||||||
: msg_(std::move(msg)) {}
|
: msg_(std::move(msg)) {}
|
||||||
|
|
||||||
spdlog_ex::spdlog_ex(const std::string &msg, int last_errno) {
|
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;
|
memory_buf_t outbuf;
|
||||||
fmt::format_system_error(outbuf, last_errno, msg.c_str());
|
fmt::format_system_error(outbuf, last_errno, msg.c_str());
|
||||||
msg_ = fmt::to_string(outbuf);
|
msg_ = fmt::to_string(outbuf);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *spdlog_ex::what() const noexcept { return msg_.c_str(); }
|
const char *spdlog_ex::what() const noexcept { return msg_.c_str(); }
|
||||||
|
@ -19,12 +19,12 @@ if(Catch2_FOUND)
|
|||||||
else()
|
else()
|
||||||
message(STATUS "Bundled version of Catch will be downloaded and used.")
|
message(STATUS "Bundled version of Catch will be downloaded and used.")
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
FetchContent_Declare(Catch2
|
FetchContent_Declare(
|
||||||
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
|
Catch2 GIT_REPOSITORY https://github.com/catchorg/Catch2.git
|
||||||
GIT_TAG 53d0d913a422d356b23dd927547febdf69ee9081 # v3.5.0
|
GIT_TAG 53d0d913a422d356b23dd927547febdf69ee9081 # v3.5.0
|
||||||
)
|
)
|
||||||
FetchContent_MakeAvailable(Catch2)
|
FetchContent_MakeAvailable(Catch2)
|
||||||
set_target_properties(Catch2 Catch2WithMain PROPERTIES FOLDER "third-party")
|
set_target_properties(Catch2 Catch2WithMain PROPERTIES FOLDER "third-party")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(SPDLOG_UTESTS_SOURCES
|
set(SPDLOG_UTESTS_SOURCES
|
||||||
@ -52,7 +52,8 @@ set(SPDLOG_UTESTS_SOURCES
|
|||||||
test_source_location.cpp
|
test_source_location.cpp
|
||||||
test_no_source_location.cpp
|
test_no_source_location.cpp
|
||||||
test_log_level.cpp
|
test_log_level.cpp
|
||||||
test_include_sinks.cpp)
|
test_include_sinks.cpp
|
||||||
|
test_bin_to_hex.cpp)
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
list(APPEND SPDLOG_UTESTS_SOURCES test_eventlog.cpp)
|
list(APPEND SPDLOG_UTESTS_SOURCES test_eventlog.cpp)
|
||||||
@ -66,10 +67,6 @@ if(systemd_FOUND)
|
|||||||
list(APPEND SPDLOG_UTESTS_SOURCES test_systemd.cpp)
|
list(APPEND SPDLOG_UTESTS_SOURCES test_systemd.cpp)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(NOT SPDLOG_USE_STD_FORMAT)
|
|
||||||
list(APPEND SPDLOG_UTESTS_SOURCES test_bin_to_hex.cpp)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
|
||||||
function(spdlog_prepare_test test_target spdlog_lib)
|
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)
|
target_link_libraries(${test_target} PRIVATE Catch2::Catch2WithMain)
|
||||||
if(SPDLOG_SANITIZE_ADDRESS)
|
if(SPDLOG_SANITIZE_ADDRESS)
|
||||||
spdlog_enable_addr_sanitizer(${test_target})
|
spdlog_enable_addr_sanitizer(${test_target})
|
||||||
elseif (SPDLOG_SANITIZE_THREAD)
|
elseif(SPDLOG_SANITIZE_THREAD)
|
||||||
spdlog_enable_thread_sanitizer(${test_target})
|
spdlog_enable_thread_sanitizer(${test_target})
|
||||||
endif ()
|
endif()
|
||||||
add_test(NAME ${test_target} COMMAND ${test_target})
|
add_test(NAME ${test_target} COMMAND ${test_target})
|
||||||
set_tests_properties(${test_target} PROPERTIES RUN_SERIAL ON)
|
set_tests_properties(${test_target} PROPERTIES RUN_SERIAL ON)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
@ -81,8 +81,7 @@ TEST_CASE("dir_name", "[create_dir]") {
|
|||||||
// clang-format off
|
// clang-format off
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <fileapi.h>
|
#include <fileapi.h>
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
|
|
||||||
std::string get_full_path(const std::string &relative_folder_path) {
|
std::string get_full_path(const std::string &relative_folder_path) {
|
||||||
char full_path[MAX_PATH];
|
char full_path[MAX_PATH];
|
||||||
|
@ -6,11 +6,7 @@
|
|||||||
#include "spdlog/sinks/daily_file_sink.h"
|
#include "spdlog/sinks/daily_file_sink.h"
|
||||||
#include "spdlog/sinks/rotating_file_sink.h"
|
#include "spdlog/sinks/rotating_file_sink.h"
|
||||||
|
|
||||||
#ifdef SPDLOG_USE_STD_FORMAT
|
using filename_memory_buf_t = spdlog::memory_buf_t;
|
||||||
using filename_memory_buf_t = std::basic_string<spdlog::filename_t::value_type>;
|
|
||||||
#else
|
|
||||||
using filename_memory_buf_t = fmt::basic_memory_buffer<spdlog::filename_t::value_type, 250>;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef SPDLOG_WCHAR_FILENAMES
|
#ifdef SPDLOG_WCHAR_FILENAMES
|
||||||
std::string filename_buf_to_utf8string(const filename_memory_buf_t &w) {
|
std::string filename_buf_to_utf8string(const filename_memory_buf_t &w) {
|
||||||
|
@ -18,7 +18,6 @@ protected:
|
|||||||
};
|
};
|
||||||
struct custom_ex {};
|
struct custom_ex {};
|
||||||
|
|
||||||
#if !defined(SPDLOG_USE_STD_FORMAT) // std formt doesn't fully support runtime format strings
|
|
||||||
TEST_CASE("default_error_handler", "[errors]") {
|
TEST_CASE("default_error_handler", "[errors]") {
|
||||||
prepare_logdir();
|
prepare_logdir();
|
||||||
spdlog::filename_t filename = SPDLOG_FILENAME_T(SIMPLE_LOG);
|
spdlog::filename_t filename = SPDLOG_FILENAME_T(SIMPLE_LOG);
|
||||||
@ -45,7 +44,6 @@ TEST_CASE("custom_error_handler", "[errors]") {
|
|||||||
logger->info("Good message #2");
|
logger->info("Good message #2");
|
||||||
require_message_count(SIMPLE_LOG, 2);
|
require_message_count(SIMPLE_LOG, 2);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
TEST_CASE("default_error_handler2", "[errors]") {
|
TEST_CASE("default_error_handler2", "[errors]") {
|
||||||
spdlog::drop_all();
|
spdlog::drop_all();
|
||||||
@ -61,7 +59,6 @@ TEST_CASE("flush_error_handler", "[errors]") {
|
|||||||
REQUIRE_THROWS_AS(logger->flush(), custom_ex);
|
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]") {
|
TEST_CASE("async_error_handler", "[errors]") {
|
||||||
prepare_logdir();
|
prepare_logdir();
|
||||||
std::string err_msg("log failed with some msg");
|
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_message_count(SIMPLE_ASYNC_LOG, 2);
|
||||||
REQUIRE(file_contents("test_logs/custom_err.txt") == err_msg);
|
REQUIRE(file_contents("test_logs/custom_err.txt") == err_msg);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
// Make sure async error handler is executed
|
// Make sure async error handler is executed
|
||||||
TEST_CASE("async_error_handler2", "[errors]") {
|
TEST_CASE("async_error_handler2", "[errors]") {
|
||||||
|
Loading…
Reference in New Issue
Block a user