mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-28 17:19:34 +08:00
clang format
This commit is contained in:
206
CMakeLists.txt
206
CMakeLists.txt
@@ -18,39 +18,38 @@ include(GNUInstallDirs)
|
|||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
# Set default build to release
|
# Set default build to release
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
||||||
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose Release or Debug" FORCE)
|
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose Release or Debug" FORCE)
|
||||||
endif ()
|
endif()
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
# Compiler config
|
# Compiler config
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
if (SPDLOG_USE_STD_FORMAT)
|
if(SPDLOG_USE_STD_FORMAT)
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
elseif (NOT CMAKE_CXX_STANDARD)
|
elseif(NOT CMAKE_CXX_STANDARD)
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
endif ()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
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")
|
||||||
set(CMAKE_CXX_EXTENSIONS ON)
|
set(CMAKE_CXX_EXTENSIONS ON)
|
||||||
endif ()
|
endif()
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
# Set SPDLOG_MASTER_PROJECT to ON if we are building spdlog
|
# Set SPDLOG_MASTER_PROJECT to ON if we are building spdlog
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
# Check if spdlog is being used directly or via add_subdirectory, but allow overriding
|
# Check if spdlog is being used directly or via add_subdirectory, but allow overriding
|
||||||
if (NOT DEFINED SPDLOG_MASTER_PROJECT)
|
if(NOT DEFINED SPDLOG_MASTER_PROJECT)
|
||||||
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
||||||
set(SPDLOG_MASTER_PROJECT ON)
|
set(SPDLOG_MASTER_PROJECT ON)
|
||||||
else ()
|
else()
|
||||||
set(SPDLOG_MASTER_PROJECT OFF)
|
set(SPDLOG_MASTER_PROJECT OFF)
|
||||||
endif ()
|
endif()
|
||||||
endif ()
|
endif()
|
||||||
|
|
||||||
option(SPDLOG_BUILD_ALL "Build all artifacts" OFF)
|
option(SPDLOG_BUILD_ALL "Build all artifacts" OFF)
|
||||||
|
|
||||||
@@ -77,9 +76,9 @@ option(SPDLOG_BUILD_BENCH "Build benchmarks (Requires https://github.com/google/
|
|||||||
# sanitizer options
|
# sanitizer options
|
||||||
option(SPDLOG_SANITIZE_ADDRESS "Enable address sanitizer in tests" OFF)
|
option(SPDLOG_SANITIZE_ADDRESS "Enable address sanitizer in tests" OFF)
|
||||||
option(SPDLOG_SANITIZE_THREAD "Enable thread sanitizer in tests" OFF)
|
option(SPDLOG_SANITIZE_THREAD "Enable thread sanitizer in tests" OFF)
|
||||||
if (SPDLOG_SANITIZE_ADDRESS AND SPDLOG_SANITIZE_THREAD)
|
if(SPDLOG_SANITIZE_ADDRESS AND SPDLOG_SANITIZE_THREAD)
|
||||||
message(FATAL_ERROR "SPDLOG_SANITIZE_ADDRESS and SPDLOG_SANITIZE_THREAD are mutually exclusive")
|
message(FATAL_ERROR "SPDLOG_SANITIZE_ADDRESS and SPDLOG_SANITIZE_THREAD are mutually exclusive")
|
||||||
endif ()
|
endif()
|
||||||
|
|
||||||
# warning options
|
# warning options
|
||||||
option(SPDLOG_BUILD_WARNINGS "Enable compiler warnings" OFF)
|
option(SPDLOG_BUILD_WARNINGS "Enable compiler warnings" OFF)
|
||||||
@@ -92,38 +91,38 @@ option(SPDLOG_FMT_EXTERNAL "Use external fmt library instead of bundled" OFF)
|
|||||||
option(SPDLOG_FMT_EXTERNAL_HO "Use external fmt header-only library instead of bundled" OFF)
|
option(SPDLOG_FMT_EXTERNAL_HO "Use external fmt header-only library instead of bundled" 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_FMT_EXTERNAL AND SPDLOG_FMT_EXTERNAL_HO)
|
if(SPDLOG_FMT_EXTERNAL AND SPDLOG_FMT_EXTERNAL_HO)
|
||||||
message(FATAL_ERROR "SPDLOG_FMT_EXTERNAL and SPDLOG_FMT_EXTERNAL_HO are mutually exclusive")
|
message(FATAL_ERROR "SPDLOG_FMT_EXTERNAL and SPDLOG_FMT_EXTERNAL_HO are mutually exclusive")
|
||||||
endif ()
|
endif()
|
||||||
|
|
||||||
if (SPDLOG_USE_STD_FORMAT AND SPDLOG_FMT_EXTERNAL_HO)
|
if(SPDLOG_USE_STD_FORMAT AND SPDLOG_FMT_EXTERNAL_HO)
|
||||||
message(FATAL_ERROR "SPDLOG_USE_STD_FORMAT and SPDLOG_FMT_EXTERNAL_HO are mutually exclusive")
|
message(FATAL_ERROR "SPDLOG_USE_STD_FORMAT and SPDLOG_FMT_EXTERNAL_HO are mutually exclusive")
|
||||||
endif ()
|
endif()
|
||||||
|
|
||||||
if (SPDLOG_USE_STD_FORMAT AND SPDLOG_FMT_EXTERNAL)
|
if(SPDLOG_USE_STD_FORMAT AND SPDLOG_FMT_EXTERNAL)
|
||||||
message(FATAL_ERROR "SPDLOG_USE_STD_FORMAT and SPDLOG_FMT_EXTERNAL are mutually exclusive")
|
message(FATAL_ERROR "SPDLOG_USE_STD_FORMAT and SPDLOG_FMT_EXTERNAL are mutually exclusive")
|
||||||
endif ()
|
endif()
|
||||||
|
|
||||||
# misc tweakme options
|
# misc tweakme options
|
||||||
if (WIN32)
|
if(WIN32)
|
||||||
option(SPDLOG_WCHAR_SUPPORT "Support wchar api" OFF)
|
option(SPDLOG_WCHAR_SUPPORT "Support wchar api" OFF)
|
||||||
option(SPDLOG_WCHAR_FILENAMES "Support wchar filenames" OFF)
|
option(SPDLOG_WCHAR_FILENAMES "Support wchar filenames" OFF)
|
||||||
option(SPDLOG_WCHAR_CONSOLE "Support wchar output to console" OFF)
|
option(SPDLOG_WCHAR_CONSOLE "Support wchar output to console" OFF)
|
||||||
else ()
|
else()
|
||||||
set(SPDLOG_WCHAR_SUPPORT OFF CACHE BOOL "non supported option" FORCE)
|
set(SPDLOG_WCHAR_SUPPORT OFF CACHE BOOL "non supported option" FORCE)
|
||||||
set(SPDLOG_WCHAR_FILENAMES OFF CACHE BOOL "non supported option" FORCE)
|
set(SPDLOG_WCHAR_FILENAMES OFF CACHE BOOL "non supported option" FORCE)
|
||||||
set(SPDLOG_WCHAR_CONSOLE OFF CACHE BOOL "non supported option" FORCE)
|
set(SPDLOG_WCHAR_CONSOLE OFF CACHE BOOL "non supported option" FORCE)
|
||||||
endif ()
|
endif()
|
||||||
|
|
||||||
if (MSVC)
|
if(MSVC)
|
||||||
option(SPDLOG_MSVC_UTF8 "Enable/disable msvc /utf-8 flag required by fmt lib" ON)
|
option(SPDLOG_MSVC_UTF8 "Enable/disable msvc /utf-8 flag required by fmt lib" ON)
|
||||||
endif ()
|
endif()
|
||||||
|
|
||||||
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
||||||
option(SPDLOG_CLOCK_COARSE "Use CLOCK_REALTIME_COARSE instead of the regular clock," OFF)
|
option(SPDLOG_CLOCK_COARSE "Use CLOCK_REALTIME_COARSE instead of the regular clock," OFF)
|
||||||
else ()
|
else()
|
||||||
set(SPDLOG_CLOCK_COARSE OFF CACHE BOOL "non supported option" FORCE)
|
set(SPDLOG_CLOCK_COARSE OFF CACHE BOOL "non supported option" FORCE)
|
||||||
endif ()
|
endif()
|
||||||
|
|
||||||
option(SPDLOG_PREVENT_CHILD_FD "Prevent from child processes to inherit log file descriptors" OFF)
|
option(SPDLOG_PREVENT_CHILD_FD "Prevent from child processes to inherit log file descriptors" OFF)
|
||||||
option(SPDLOG_NO_THREAD_ID "prevent spdlog from querying the thread id on each log call if thread id is not needed" OFF)
|
option(SPDLOG_NO_THREAD_ID "prevent spdlog from querying the thread id on each log call if thread id is not needed" OFF)
|
||||||
@@ -138,15 +137,15 @@ option(SPDLOG_FWRITE_UNLOCKED "Use the unlocked variant of fwrite. Leave this on
|
|||||||
# clang-tidy
|
# clang-tidy
|
||||||
option(SPDLOG_TIDY "run clang-tidy" OFF)
|
option(SPDLOG_TIDY "run clang-tidy" OFF)
|
||||||
|
|
||||||
if (SPDLOG_TIDY)
|
if(SPDLOG_TIDY)
|
||||||
set(CMAKE_CXX_CLANG_TIDY "clang-tidy")
|
set(CMAKE_CXX_CLANG_TIDY "clang-tidy")
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
message(STATUS "Enabled clang-tidy")
|
message(STATUS "Enabled clang-tidy")
|
||||||
endif ()
|
endif()
|
||||||
|
|
||||||
if (SPDLOG_BUILD_PIC)
|
if(SPDLOG_BUILD_PIC)
|
||||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||||
endif ()
|
endif()
|
||||||
|
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
message(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
|
message(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
|
||||||
@@ -155,34 +154,34 @@ message(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
|
|||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
set(SPDLOG_SRCS src/spdlog.cpp src/stdout_sinks.cpp src/color_sinks.cpp src/file_sinks.cpp src/async.cpp src/cfg.cpp)
|
set(SPDLOG_SRCS src/spdlog.cpp src/stdout_sinks.cpp src/color_sinks.cpp src/file_sinks.cpp src/async.cpp src/cfg.cpp)
|
||||||
|
|
||||||
if (NOT SPDLOG_USE_STD_FORMAT AND NOT SPDLOG_FMT_EXTERNAL AND NOT SPDLOG_FMT_EXTERNAL_HO)
|
if(NOT SPDLOG_USE_STD_FORMAT AND NOT SPDLOG_FMT_EXTERNAL AND NOT SPDLOG_FMT_EXTERNAL_HO)
|
||||||
list(APPEND SPDLOG_SRCS src/bundled_fmtlib_format.cpp)
|
list(APPEND SPDLOG_SRCS src/bundled_fmtlib_format.cpp)
|
||||||
endif ()
|
endif()
|
||||||
|
|
||||||
if (SPDLOG_BUILD_SHARED OR BUILD_SHARED_LIBS)
|
if(SPDLOG_BUILD_SHARED OR BUILD_SHARED_LIBS)
|
||||||
if (WIN32)
|
if(WIN32)
|
||||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc @ONLY)
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc @ONLY)
|
||||||
list(APPEND SPDLOG_SRCS ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
|
list(APPEND SPDLOG_SRCS ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
|
||||||
endif ()
|
endif()
|
||||||
add_library(spdlog SHARED ${SPDLOG_SRCS} ${SPDLOG_ALL_HEADERS})
|
add_library(spdlog SHARED ${SPDLOG_SRCS} ${SPDLOG_ALL_HEADERS})
|
||||||
target_compile_definitions(spdlog PUBLIC SPDLOG_SHARED_LIB)
|
target_compile_definitions(spdlog PUBLIC SPDLOG_SHARED_LIB)
|
||||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||||
target_compile_options(spdlog PUBLIC $<$<AND:$<CXX_COMPILER_ID:MSVC>,$<NOT:$<COMPILE_LANGUAGE:CUDA>>>:/wd4251
|
target_compile_options(spdlog PUBLIC $<$<AND:$<CXX_COMPILER_ID:MSVC>,$<NOT:$<COMPILE_LANGUAGE:CUDA>>>:/wd4251
|
||||||
/wd4275>)
|
/wd4275>)
|
||||||
endif ()
|
endif()
|
||||||
if (NOT SPDLOG_USE_STD_FORMAT AND NOT SPDLOG_FMT_EXTERNAL AND NOT SPDLOG_FMT_EXTERNAL_HO)
|
if(NOT SPDLOG_USE_STD_FORMAT AND NOT SPDLOG_FMT_EXTERNAL AND NOT SPDLOG_FMT_EXTERNAL_HO)
|
||||||
target_compile_definitions(spdlog PRIVATE FMT_LIB_EXPORT PUBLIC FMT_SHARED)
|
target_compile_definitions(spdlog PRIVATE FMT_LIB_EXPORT PUBLIC FMT_SHARED)
|
||||||
endif ()
|
endif()
|
||||||
else ()
|
else()
|
||||||
add_library(spdlog STATIC ${SPDLOG_SRCS} ${SPDLOG_ALL_HEADERS})
|
add_library(spdlog STATIC ${SPDLOG_SRCS} ${SPDLOG_ALL_HEADERS})
|
||||||
endif ()
|
endif()
|
||||||
|
|
||||||
add_library(spdlog::spdlog ALIAS spdlog)
|
add_library(spdlog::spdlog ALIAS spdlog)
|
||||||
|
|
||||||
set(SPDLOG_INCLUDES_LEVEL "")
|
set(SPDLOG_INCLUDES_LEVEL "")
|
||||||
if (SPDLOG_SYSTEM_INCLUDES)
|
if(SPDLOG_SYSTEM_INCLUDES)
|
||||||
set(SPDLOG_INCLUDES_LEVEL "SYSTEM")
|
set(SPDLOG_INCLUDES_LEVEL "SYSTEM")
|
||||||
endif ()
|
endif()
|
||||||
|
|
||||||
target_compile_definitions(spdlog PUBLIC SPDLOG_COMPILED_LIB)
|
target_compile_definitions(spdlog PUBLIC SPDLOG_COMPILED_LIB)
|
||||||
target_include_directories(spdlog ${SPDLOG_INCLUDES_LEVEL} PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
|
target_include_directories(spdlog ${SPDLOG_INCLUDES_LEVEL} PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
|
||||||
@@ -194,17 +193,17 @@ set_target_properties(spdlog PROPERTIES VERSION ${SPDLOG_VERSION} SOVERSION
|
|||||||
${SPDLOG_VERSION_MAJOR}.${SPDLOG_VERSION_MINOR})
|
${SPDLOG_VERSION_MAJOR}.${SPDLOG_VERSION_MINOR})
|
||||||
set_target_properties(spdlog PROPERTIES DEBUG_POSTFIX d)
|
set_target_properties(spdlog PROPERTIES DEBUG_POSTFIX d)
|
||||||
|
|
||||||
if (COMMAND target_precompile_headers AND SPDLOG_ENABLE_PCH)
|
if(COMMAND target_precompile_headers AND SPDLOG_ENABLE_PCH)
|
||||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/pch.h.in ${PROJECT_BINARY_DIR}/spdlog_pch.h @ONLY)
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/pch.h.in ${PROJECT_BINARY_DIR}/spdlog_pch.h @ONLY)
|
||||||
target_precompile_headers(spdlog PRIVATE ${PROJECT_BINARY_DIR}/spdlog_pch.h)
|
target_precompile_headers(spdlog PRIVATE ${PROJECT_BINARY_DIR}/spdlog_pch.h)
|
||||||
endif ()
|
endif()
|
||||||
|
|
||||||
# sanitizer support
|
# sanitizer support
|
||||||
if (SPDLOG_SANITIZE_ADDRESS)
|
if(SPDLOG_SANITIZE_ADDRESS)
|
||||||
spdlog_enable_addr_sanitizer(spdlog)
|
spdlog_enable_addr_sanitizer(spdlog)
|
||||||
elseif (SPDLOG_SANITIZE_THREAD)
|
elseif(SPDLOG_SANITIZE_THREAD)
|
||||||
spdlog_enable_thread_sanitizer(spdlog)
|
spdlog_enable_thread_sanitizer(spdlog)
|
||||||
endif ()
|
endif()
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
# Header only version
|
# Header only version
|
||||||
@@ -220,55 +219,55 @@ target_link_libraries(spdlog_header_only INTERFACE Threads::Threads)
|
|||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
# Use fmt package if using external fmt
|
# Use fmt package if using external fmt
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
if (SPDLOG_FMT_EXTERNAL OR SPDLOG_FMT_EXTERNAL_HO)
|
if(SPDLOG_FMT_EXTERNAL OR SPDLOG_FMT_EXTERNAL_HO)
|
||||||
if (NOT TARGET fmt::fmt)
|
if(NOT TARGET fmt::fmt)
|
||||||
find_package(fmt CONFIG REQUIRED)
|
find_package(fmt CONFIG REQUIRED)
|
||||||
endif ()
|
endif()
|
||||||
target_compile_definitions(spdlog PUBLIC SPDLOG_FMT_EXTERNAL)
|
target_compile_definitions(spdlog PUBLIC SPDLOG_FMT_EXTERNAL)
|
||||||
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_FMT_EXTERNAL)
|
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_FMT_EXTERNAL)
|
||||||
|
|
||||||
# use external fmt-header-only
|
# use external fmt-header-only
|
||||||
if (SPDLOG_FMT_EXTERNAL_HO)
|
if(SPDLOG_FMT_EXTERNAL_HO)
|
||||||
target_link_libraries(spdlog PUBLIC fmt::fmt-header-only)
|
target_link_libraries(spdlog PUBLIC fmt::fmt-header-only)
|
||||||
target_link_libraries(spdlog_header_only INTERFACE fmt::fmt-header-only)
|
target_link_libraries(spdlog_header_only INTERFACE fmt::fmt-header-only)
|
||||||
else () # use external compile fmt
|
else() # use external compile fmt
|
||||||
target_link_libraries(spdlog PUBLIC fmt::fmt)
|
target_link_libraries(spdlog PUBLIC fmt::fmt)
|
||||||
target_link_libraries(spdlog_header_only INTERFACE fmt::fmt)
|
target_link_libraries(spdlog_header_only INTERFACE fmt::fmt)
|
||||||
endif ()
|
endif()
|
||||||
|
|
||||||
set(PKG_CONFIG_REQUIRES fmt) # add dependency to pkg-config
|
set(PKG_CONFIG_REQUIRES fmt) # add dependency to pkg-config
|
||||||
endif ()
|
endif()
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
# Check if fwrite_unlocked/_fwrite_nolock is available
|
# Check if fwrite_unlocked/_fwrite_nolock is available
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
if (SPDLOG_FWRITE_UNLOCKED)
|
if(SPDLOG_FWRITE_UNLOCKED)
|
||||||
include(CheckSymbolExists)
|
include(CheckSymbolExists)
|
||||||
if (WIN32)
|
if(WIN32)
|
||||||
check_symbol_exists(_fwrite_nolock "stdio.h" HAVE_FWRITE_UNLOCKED)
|
check_symbol_exists(_fwrite_nolock "stdio.h" HAVE_FWRITE_UNLOCKED)
|
||||||
else ()
|
else()
|
||||||
check_symbol_exists(fwrite_unlocked "stdio.h" HAVE_FWRITE_UNLOCKED)
|
check_symbol_exists(fwrite_unlocked "stdio.h" HAVE_FWRITE_UNLOCKED)
|
||||||
endif ()
|
endif()
|
||||||
if (HAVE_FWRITE_UNLOCKED)
|
if(HAVE_FWRITE_UNLOCKED)
|
||||||
target_compile_definitions(spdlog PRIVATE SPDLOG_FWRITE_UNLOCKED)
|
target_compile_definitions(spdlog PRIVATE SPDLOG_FWRITE_UNLOCKED)
|
||||||
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_FWRITE_UNLOCKED)
|
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_FWRITE_UNLOCKED)
|
||||||
endif ()
|
endif()
|
||||||
endif ()
|
endif()
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
# Add required libraries for Android CMake build
|
# Add required libraries for Android CMake build
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
if (ANDROID)
|
if(ANDROID)
|
||||||
target_link_libraries(spdlog PUBLIC log)
|
target_link_libraries(spdlog PUBLIC log)
|
||||||
target_link_libraries(spdlog_header_only INTERFACE log)
|
target_link_libraries(spdlog_header_only INTERFACE log)
|
||||||
endif ()
|
endif()
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
# Misc definitions according to tweak options
|
# Misc definitions according to tweak options
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
set(SPDLOG_WCHAR_TO_UTF8_SUPPORT ${SPDLOG_WCHAR_SUPPORT})
|
set(SPDLOG_WCHAR_TO_UTF8_SUPPORT ${SPDLOG_WCHAR_SUPPORT})
|
||||||
set(SPDLOG_UTF8_TO_WCHAR_CONSOLE ${SPDLOG_WCHAR_CONSOLE})
|
set(SPDLOG_UTF8_TO_WCHAR_CONSOLE ${SPDLOG_WCHAR_CONSOLE})
|
||||||
foreach (
|
foreach(
|
||||||
SPDLOG_OPTION
|
SPDLOG_OPTION
|
||||||
SPDLOG_WCHAR_TO_UTF8_SUPPORT
|
SPDLOG_WCHAR_TO_UTF8_SUPPORT
|
||||||
SPDLOG_UTF8_TO_WCHAR_CONSOLE
|
SPDLOG_UTF8_TO_WCHAR_CONSOLE
|
||||||
@@ -281,65 +280,66 @@ foreach (
|
|||||||
SPDLOG_NO_ATOMIC_LEVELS
|
SPDLOG_NO_ATOMIC_LEVELS
|
||||||
SPDLOG_DISABLE_DEFAULT_LOGGER
|
SPDLOG_DISABLE_DEFAULT_LOGGER
|
||||||
SPDLOG_USE_STD_FORMAT)
|
SPDLOG_USE_STD_FORMAT)
|
||||||
if (${SPDLOG_OPTION})
|
if(${SPDLOG_OPTION})
|
||||||
target_compile_definitions(spdlog PUBLIC ${SPDLOG_OPTION})
|
target_compile_definitions(spdlog PUBLIC ${SPDLOG_OPTION})
|
||||||
target_compile_definitions(spdlog_header_only INTERFACE ${SPDLOG_OPTION})
|
target_compile_definitions(spdlog_header_only INTERFACE ${SPDLOG_OPTION})
|
||||||
endif ()
|
endif()
|
||||||
endforeach ()
|
endforeach()
|
||||||
|
|
||||||
if (MSVC)
|
if(MSVC)
|
||||||
target_compile_options(spdlog PRIVATE "/Zc:__cplusplus")
|
target_compile_options(spdlog PRIVATE "/Zc:__cplusplus")
|
||||||
target_compile_options(spdlog_header_only INTERFACE "/Zc:__cplusplus")
|
target_compile_options(spdlog_header_only INTERFACE "/Zc:__cplusplus")
|
||||||
if (SPDLOG_MSVC_UTF8)
|
if(SPDLOG_MSVC_UTF8)
|
||||||
# fmtlib requires the /utf-8 flag when building with msvc.
|
# fmtlib requires the /utf-8 flag when building with msvc. see https://github.com/fmtlib/fmt/pull/4159 on the
|
||||||
# see https://github.com/fmtlib/fmt/pull/4159 on the purpose of the additional
|
# purpose of the additional
|
||||||
# "$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:MSVC>>"
|
# "$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:MSVC>>"
|
||||||
target_compile_options(spdlog PUBLIC $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:MSVC>>:/utf-8>)
|
target_compile_options(spdlog PUBLIC $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:MSVC>>:/utf-8>)
|
||||||
target_compile_options(spdlog_header_only INTERFACE $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:MSVC>>:/utf-8>)
|
target_compile_options(spdlog_header_only
|
||||||
endif ()
|
INTERFACE $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:MSVC>>:/utf-8>)
|
||||||
endif ()
|
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
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
if (SPDLOG_NO_EXCEPTIONS)
|
if(SPDLOG_NO_EXCEPTIONS)
|
||||||
if (NOT SPDLOG_FMT_EXTERNAL AND NOT SPDLOG_FMT_EXTERNAL_HO)
|
if(NOT SPDLOG_FMT_EXTERNAL AND NOT SPDLOG_FMT_EXTERNAL_HO)
|
||||||
target_compile_definitions(spdlog PUBLIC FMT_USE_EXCEPTIONS=0)
|
target_compile_definitions(spdlog PUBLIC FMT_USE_EXCEPTIONS=0)
|
||||||
endif ()
|
endif()
|
||||||
if (NOT MSVC)
|
if(NOT MSVC)
|
||||||
target_compile_options(spdlog PRIVATE -fno-exceptions)
|
target_compile_options(spdlog PRIVATE -fno-exceptions)
|
||||||
else ()
|
else()
|
||||||
target_compile_options(spdlog PRIVATE /EHs-c-)
|
target_compile_options(spdlog PRIVATE /EHs-c-)
|
||||||
target_compile_definitions(spdlog PRIVATE _HAS_EXCEPTIONS=0)
|
target_compile_definitions(spdlog PRIVATE _HAS_EXCEPTIONS=0)
|
||||||
endif ()
|
endif()
|
||||||
endif ()
|
endif()
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
# Build binaries
|
# Build binaries
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
if (SPDLOG_BUILD_EXAMPLE OR SPDLOG_BUILD_EXAMPLE_HO OR SPDLOG_BUILD_ALL)
|
if(SPDLOG_BUILD_EXAMPLE OR SPDLOG_BUILD_EXAMPLE_HO OR SPDLOG_BUILD_ALL)
|
||||||
message(STATUS "Generating example(s)")
|
message(STATUS "Generating example(s)")
|
||||||
add_subdirectory(example)
|
add_subdirectory(example)
|
||||||
spdlog_enable_warnings(example)
|
spdlog_enable_warnings(example)
|
||||||
if (SPDLOG_BUILD_EXAMPLE_HO)
|
if(SPDLOG_BUILD_EXAMPLE_HO)
|
||||||
spdlog_enable_warnings(example_header_only)
|
spdlog_enable_warnings(example_header_only)
|
||||||
endif ()
|
endif()
|
||||||
endif ()
|
endif()
|
||||||
|
|
||||||
if (SPDLOG_BUILD_TESTS OR SPDLOG_BUILD_TESTS_HO OR SPDLOG_BUILD_ALL)
|
if(SPDLOG_BUILD_TESTS OR SPDLOG_BUILD_TESTS_HO OR SPDLOG_BUILD_ALL)
|
||||||
message(STATUS "Generating tests")
|
message(STATUS "Generating tests")
|
||||||
enable_testing()
|
enable_testing()
|
||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
endif ()
|
endif()
|
||||||
|
|
||||||
if (SPDLOG_BUILD_BENCH OR SPDLOG_BUILD_ALL)
|
if(SPDLOG_BUILD_BENCH OR SPDLOG_BUILD_ALL)
|
||||||
message(STATUS "Generating benchmarks")
|
message(STATUS "Generating benchmarks")
|
||||||
add_subdirectory(bench)
|
add_subdirectory(bench)
|
||||||
endif ()
|
endif()
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
# Install
|
# Install
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
if (SPDLOG_INSTALL)
|
if(SPDLOG_INSTALL)
|
||||||
message(STATUS "Generating install")
|
message(STATUS "Generating install")
|
||||||
set(project_config_in "${CMAKE_CURRENT_LIST_DIR}/cmake/spdlogConfig.cmake.in")
|
set(project_config_in "${CMAKE_CURRENT_LIST_DIR}/cmake/spdlogConfig.cmake.in")
|
||||||
set(project_config_out "${CMAKE_CURRENT_BINARY_DIR}/spdlogConfig.cmake")
|
set(project_config_out "${CMAKE_CURRENT_BINARY_DIR}/spdlogConfig.cmake")
|
||||||
@@ -360,24 +360,24 @@ if (SPDLOG_INSTALL)
|
|||||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||||
|
|
||||||
if (NOT SPDLOG_USE_STD_FORMAT AND NOT SPDLOG_FMT_EXTERNAL AND NOT SPDLOG_FMT_EXTERNAL_HO)
|
if(NOT SPDLOG_USE_STD_FORMAT AND NOT SPDLOG_FMT_EXTERNAL AND NOT SPDLOG_FMT_EXTERNAL_HO)
|
||||||
install(DIRECTORY include/${PROJECT_NAME}/fmt/bundled/
|
install(DIRECTORY include/${PROJECT_NAME}/fmt/bundled/
|
||||||
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/fmt/bundled/")
|
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/fmt/bundled/")
|
||||||
endif ()
|
endif()
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
# Install pkg-config file
|
# Install pkg-config file
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
if (IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}")
|
if(IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}")
|
||||||
set(PKG_CONFIG_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}")
|
set(PKG_CONFIG_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}")
|
||||||
else ()
|
else()
|
||||||
set(PKG_CONFIG_INCLUDEDIR "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
|
set(PKG_CONFIG_INCLUDEDIR "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
|
||||||
endif ()
|
endif()
|
||||||
if (IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
|
if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
|
||||||
set(PKG_CONFIG_LIBDIR "${CMAKE_INSTALL_LIBDIR}")
|
set(PKG_CONFIG_LIBDIR "${CMAKE_INSTALL_LIBDIR}")
|
||||||
else ()
|
else()
|
||||||
set(PKG_CONFIG_LIBDIR "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
|
set(PKG_CONFIG_LIBDIR "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
|
||||||
endif ()
|
endif()
|
||||||
get_target_property(PKG_CONFIG_DEFINES spdlog INTERFACE_COMPILE_DEFINITIONS)
|
get_target_property(PKG_CONFIG_DEFINES spdlog INTERFACE_COMPILE_DEFINITIONS)
|
||||||
string(REPLACE ";" " -D" PKG_CONFIG_DEFINES "${PKG_CONFIG_DEFINES}")
|
string(REPLACE ";" " -D" PKG_CONFIG_DEFINES "${PKG_CONFIG_DEFINES}")
|
||||||
string(CONCAT PKG_CONFIG_DEFINES "-D" "${PKG_CONFIG_DEFINES}")
|
string(CONCAT PKG_CONFIG_DEFINES "-D" "${PKG_CONFIG_DEFINES}")
|
||||||
@@ -401,4 +401,4 @@ if (SPDLOG_INSTALL)
|
|||||||
# Support creation of installable packages
|
# Support creation of installable packages
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
include(cmake/spdlogCPack.cmake)
|
include(cmake/spdlogCPack.cmake)
|
||||||
endif ()
|
endif()
|
||||||
|
@@ -269,7 +269,7 @@ void multi_sink_example() {
|
|||||||
struct my_type {
|
struct my_type {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
explicit my_type(int i)
|
explicit my_type(int i)
|
||||||
: i(i){}
|
: i(i) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef SPDLOG_USE_STD_FORMAT // when using fmtlib
|
#ifndef SPDLOG_USE_STD_FORMAT // when using fmtlib
|
||||||
@@ -382,14 +382,14 @@ void replace_default_logger_example() {
|
|||||||
spdlog::set_default_logger(old_logger);
|
spdlog::set_default_logger(old_logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mapped Diagnostic Context (MDC) is a map that stores key-value pairs (string values) in thread local storage.
|
// Mapped Diagnostic Context (MDC) is a map that stores key-value pairs (string values) in thread
|
||||||
// Each thread maintains its own MDC, which loggers use to append diagnostic information to log outputs.
|
// local storage. Each thread maintains its own MDC, which loggers use to append diagnostic
|
||||||
// Note: it is not supported in asynchronous mode due to its reliance on thread-local storage.
|
// information to log outputs. Note: it is not supported in asynchronous mode due to its reliance on
|
||||||
|
// thread-local storage.
|
||||||
|
|
||||||
#ifndef SPDLOG_NO_TLS
|
#ifndef SPDLOG_NO_TLS
|
||||||
#include "spdlog/mdc.h"
|
#include "spdlog/mdc.h"
|
||||||
void mdc_example()
|
void mdc_example() {
|
||||||
{
|
|
||||||
spdlog::mdc::put("key1", "value1");
|
spdlog::mdc::put("key1", "value1");
|
||||||
spdlog::mdc::put("key2", "value2");
|
spdlog::mdc::put("key2", "value2");
|
||||||
// if not using the default format, you can use the %& formatter to print mdc data as well
|
// if not using the default format, you can use the %& formatter to print mdc data as well
|
||||||
|
@@ -89,8 +89,7 @@ inline void init_thread_pool(size_t q_size,
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline void init_thread_pool(size_t q_size, size_t thread_count) {
|
inline void init_thread_pool(size_t q_size, size_t thread_count) {
|
||||||
init_thread_pool(
|
init_thread_pool(q_size, thread_count, [] {}, [] {});
|
||||||
q_size, thread_count, [] {}, [] {});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the global thread pool.
|
// get the global thread pool.
|
||||||
|
@@ -33,7 +33,7 @@ SPDLOG_INLINE spdlog::async_logger::async_logger(std::string logger_name,
|
|||||||
// send the log message to the thread pool
|
// send the log message to the thread pool
|
||||||
SPDLOG_INLINE void spdlog::async_logger::sink_it_(const details::log_msg &msg){
|
SPDLOG_INLINE void spdlog::async_logger::sink_it_(const details::log_msg &msg){
|
||||||
SPDLOG_TRY{if (auto pool_ptr = thread_pool_.lock()){
|
SPDLOG_TRY{if (auto pool_ptr = thread_pool_.lock()){
|
||||||
pool_ptr->post_log(shared_from_this(), msg, overflow_policy_);
|
pool_ptr -> post_log(shared_from_this(), msg, overflow_policy_);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw_spdlog_ex("async log: thread pool doesn't exist anymore");
|
throw_spdlog_ex("async log: thread pool doesn't exist anymore");
|
||||||
@@ -45,7 +45,7 @@ SPDLOG_LOGGER_CATCH(msg.source)
|
|||||||
// send flush request to the thread pool
|
// send flush request to the thread pool
|
||||||
SPDLOG_INLINE void spdlog::async_logger::flush_(){
|
SPDLOG_INLINE void spdlog::async_logger::flush_(){
|
||||||
SPDLOG_TRY{if (auto pool_ptr = thread_pool_.lock()){
|
SPDLOG_TRY{if (auto pool_ptr = thread_pool_.lock()){
|
||||||
pool_ptr->post_flush(shared_from_this(), overflow_policy_);
|
pool_ptr -> post_flush(shared_from_this(), overflow_policy_);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw_spdlog_ex("async flush: thread pool doesn't exist anymore");
|
throw_spdlog_ex("async flush: thread pool doesn't exist anymore");
|
||||||
|
@@ -483,13 +483,12 @@ SPDLOG_INLINE void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// find the size to allocate for the result buffer
|
// find the size to allocate for the result buffer
|
||||||
int result_size =
|
int result_size = ::MultiByteToWideChar(CP_UTF8, 0, str.data(), str_size, NULL, 0);
|
||||||
::MultiByteToWideChar(CP_UTF8, 0, str.data(), str_size, NULL, 0);
|
|
||||||
|
|
||||||
if (result_size > 0) {
|
if (result_size > 0) {
|
||||||
target.resize(result_size);
|
target.resize(result_size);
|
||||||
result_size = ::MultiByteToWideChar(CP_UTF8, 0, str.data(), str_size, target.data(),
|
result_size =
|
||||||
result_size);
|
::MultiByteToWideChar(CP_UTF8, 0, str.data(), str_size, target.data(), result_size);
|
||||||
if (result_size > 0) {
|
if (result_size > 0) {
|
||||||
assert(result_size == target.size());
|
assert(result_size == target.size());
|
||||||
return;
|
return;
|
||||||
@@ -593,13 +592,13 @@ SPDLOG_INLINE bool fsync(FILE *fp) {
|
|||||||
// Do non-locking fwrite if possible by the os or use the regular locking fwrite
|
// Do non-locking fwrite if possible by the os or use the regular locking fwrite
|
||||||
// Return true on success.
|
// Return true on success.
|
||||||
SPDLOG_INLINE bool fwrite_bytes(const void *ptr, const size_t n_bytes, FILE *fp) {
|
SPDLOG_INLINE bool fwrite_bytes(const void *ptr, const size_t n_bytes, FILE *fp) {
|
||||||
#if defined(_WIN32) && defined(SPDLOG_FWRITE_UNLOCKED)
|
#if defined(_WIN32) && defined(SPDLOG_FWRITE_UNLOCKED)
|
||||||
return _fwrite_nolock(ptr, 1, n_bytes, fp) == n_bytes;
|
return _fwrite_nolock(ptr, 1, n_bytes, fp) == n_bytes;
|
||||||
#elif defined(SPDLOG_FWRITE_UNLOCKED)
|
#elif defined(SPDLOG_FWRITE_UNLOCKED)
|
||||||
return ::fwrite_unlocked(ptr, 1, n_bytes, fp) == n_bytes;
|
return ::fwrite_unlocked(ptr, 1, n_bytes, fp) == n_bytes;
|
||||||
#else
|
#else
|
||||||
return std::fwrite(ptr, 1, n_bytes, fp) == n_bytes;
|
return std::fwrite(ptr, 1, n_bytes, fp) == n_bytes;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace os
|
} // namespace os
|
||||||
|
@@ -38,8 +38,7 @@ SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items,
|
|||||||
: thread_pool(q_max_items, threads_n, on_thread_start, [] {}) {}
|
: thread_pool(q_max_items, threads_n, on_thread_start, [] {}) {}
|
||||||
|
|
||||||
SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items, size_t threads_n)
|
SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items, size_t threads_n)
|
||||||
: thread_pool(
|
: thread_pool(q_max_items, threads_n, [] {}, [] {}) {}
|
||||||
q_max_items, threads_n, [] {}, [] {}) {}
|
|
||||||
|
|
||||||
// message all threads to terminate gracefully join them
|
// message all threads to terminate gracefully join them
|
||||||
SPDLOG_INLINE thread_pool::~thread_pool() {
|
SPDLOG_INLINE thread_pool::~thread_pool() {
|
||||||
|
@@ -142,8 +142,8 @@ struct formatter<spdlog::details::dump_info<T>, char> {
|
|||||||
|
|
||||||
// format the given bytes range as hex
|
// format the given bytes range as hex
|
||||||
template <typename FormatContext, typename Container>
|
template <typename FormatContext, typename Container>
|
||||||
auto format(const spdlog::details::dump_info<Container> &the_range, FormatContext &ctx) const
|
auto format(const spdlog::details::dump_info<Container> &the_range,
|
||||||
-> decltype(ctx.out()) {
|
FormatContext &ctx) const -> decltype(ctx.out()) {
|
||||||
SPDLOG_CONSTEXPR const char *hex_upper = "0123456789ABCDEF";
|
SPDLOG_CONSTEXPR const char *hex_upper = "0123456789ABCDEF";
|
||||||
SPDLOG_CONSTEXPR const char *hex_lower = "0123456789abcdef";
|
SPDLOG_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;
|
||||||
|
@@ -12,12 +12,14 @@
|
|||||||
|
|
||||||
#include <spdlog/common.h>
|
#include <spdlog/common.h>
|
||||||
|
|
||||||
// MDC is a simple map of key->string values stored in thread local storage whose content will be printed by the loggers.
|
// MDC is a simple map of key->string values stored in thread local storage whose content will be
|
||||||
// Note: Not supported in async mode (thread local storage - so the async thread pool have different copy).
|
// printed by the loggers. Note: Not supported in async mode (thread local storage - so the async
|
||||||
|
// thread pool have different copy).
|
||||||
//
|
//
|
||||||
// Usage example:
|
// Usage example:
|
||||||
// spdlog::mdc::put("mdc_key_1", "mdc_value_1");
|
// spdlog::mdc::put("mdc_key_1", "mdc_value_1");
|
||||||
// spdlog::info("Hello, {}", "World!"); // => [2024-04-26 02:08:05.040] [info] [mdc_key_1:mdc_value_1] Hello, World!
|
// spdlog::info("Hello, {}", "World!"); // => [2024-04-26 02:08:05.040] [info]
|
||||||
|
// [mdc_key_1:mdc_value_1] Hello, World!
|
||||||
|
|
||||||
namespace spdlog {
|
namespace spdlog {
|
||||||
class SPDLOG_API mdc {
|
class SPDLOG_API mdc {
|
||||||
|
@@ -111,7 +111,8 @@ SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::set_color_mode_(color_mode mode
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename ConsoleMutex>
|
template <typename ConsoleMutex>
|
||||||
SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::print_ccode_(const string_view_t &color_code) const {
|
SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::print_ccode_(
|
||||||
|
const string_view_t &color_code) const {
|
||||||
details::os::fwrite_bytes(color_code.data(), color_code.size(), target_file_);
|
details::os::fwrite_bytes(color_code.data(), color_code.size(), target_file_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -27,7 +27,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void sink_it_(const details::log_msg &msg) override { callback_(msg); }
|
void sink_it_(const details::log_msg &msg) override { callback_(msg); }
|
||||||
void flush_() override{}
|
void flush_() override {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
custom_log_callback callback_;
|
custom_log_callback callback_;
|
||||||
|
@@ -99,7 +99,7 @@ SPDLOG_INLINE void rotating_file_sink<Mutex>::set_max_files(std::size_t max_file
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename Mutex>
|
template <typename Mutex>
|
||||||
std::size_t rotating_file_sink<Mutex>::get_max_files(){
|
std::size_t rotating_file_sink<Mutex>::get_max_files() {
|
||||||
std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);
|
std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);
|
||||||
return max_files_;
|
return max_files_;
|
||||||
}
|
}
|
||||||
|
@@ -109,8 +109,8 @@
|
|||||||
//
|
//
|
||||||
// #include <string_view>
|
// #include <string_view>
|
||||||
// using namespace std::string_view_literals;
|
// using namespace std::string_view_literals;
|
||||||
// #define SPDLOG_LEVEL_NAMES { "MY TRACE"sv, "MY DEBUG"sv, "MY INFO"sv, "MY WARNING"sv, "MY ERROR"sv, "MY
|
// #define SPDLOG_LEVEL_NAMES { "MY TRACE"sv, "MY DEBUG"sv, "MY INFO"sv, "MY WARNING"sv, "MY
|
||||||
// CRITICAL"sv, "OFF"sv }
|
// ERROR"sv, "MY CRITICAL"sv, "OFF"sv }
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
@@ -13,34 +13,32 @@
|
|||||||
FMT_BEGIN_NAMESPACE
|
FMT_BEGIN_NAMESPACE
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
template FMT_API auto dragonbox::to_decimal(float x) noexcept
|
template FMT_API auto dragonbox::to_decimal(float x) noexcept -> dragonbox::decimal_fp<float>;
|
||||||
-> dragonbox::decimal_fp<float>;
|
template FMT_API auto dragonbox::to_decimal(double x) noexcept -> dragonbox::decimal_fp<double>;
|
||||||
template FMT_API auto dragonbox::to_decimal(double x) noexcept
|
|
||||||
-> dragonbox::decimal_fp<double>;
|
|
||||||
|
|
||||||
#if FMT_USE_LOCALE
|
#if FMT_USE_LOCALE
|
||||||
// DEPRECATED! locale_ref in the detail namespace
|
// DEPRECATED! locale_ref in the detail namespace
|
||||||
template FMT_API locale_ref::locale_ref(const std::locale& loc);
|
template FMT_API locale_ref::locale_ref(const std::locale& loc);
|
||||||
template FMT_API auto locale_ref::get<std::locale>() const -> std::locale;
|
template FMT_API auto locale_ref::get<std::locale>() const -> std::locale;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Explicit instantiations for char.
|
// Explicit instantiations for char.
|
||||||
|
|
||||||
template FMT_API auto thousands_sep_impl(locale_ref)
|
template FMT_API auto thousands_sep_impl(locale_ref) -> thousands_sep_result<char>;
|
||||||
-> thousands_sep_result<char>;
|
|
||||||
template FMT_API auto decimal_point_impl(locale_ref) -> char;
|
template FMT_API auto decimal_point_impl(locale_ref) -> char;
|
||||||
|
|
||||||
// DEPRECATED!
|
// DEPRECATED!
|
||||||
template FMT_API void buffer<char>::append(const char*, const char*);
|
template FMT_API void buffer<char>::append(const char*, const char*);
|
||||||
|
|
||||||
// DEPRECATED!
|
// DEPRECATED!
|
||||||
template FMT_API void vformat_to(buffer<char>&, string_view,
|
template FMT_API void vformat_to(buffer<char>&,
|
||||||
typename vformat_args<>::type, locale_ref);
|
string_view,
|
||||||
|
typename vformat_args<>::type,
|
||||||
|
locale_ref);
|
||||||
|
|
||||||
// Explicit instantiations for wchar_t.
|
// Explicit instantiations for wchar_t.
|
||||||
|
|
||||||
template FMT_API auto thousands_sep_impl(locale_ref)
|
template FMT_API auto thousands_sep_impl(locale_ref) -> thousands_sep_result<wchar_t>;
|
||||||
-> thousands_sep_result<wchar_t>;
|
|
||||||
template FMT_API auto decimal_point_impl(locale_ref) -> wchar_t;
|
template FMT_API auto decimal_point_impl(locale_ref) -> wchar_t;
|
||||||
|
|
||||||
template FMT_API void buffer<wchar_t>::append(const wchar_t*, const wchar_t*);
|
template FMT_API void buffer<wchar_t>::append(const wchar_t*, const wchar_t*);
|
||||||
@@ -48,5 +46,4 @@ template FMT_API void buffer<wchar_t>::append(const wchar_t*, const wchar_t*);
|
|||||||
} // namespace detail
|
} // namespace detail
|
||||||
FMT_END_NAMESPACE
|
FMT_END_NAMESPACE
|
||||||
|
|
||||||
|
|
||||||
#endif // !SPDLOG_FMT_EXTERNAL
|
#endif // !SPDLOG_FMT_EXTERNAL
|
||||||
|
@@ -19,8 +19,8 @@ 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)
|
||||||
@@ -71,9 +71,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()
|
||||||
|
@@ -16,7 +16,8 @@ TEST_CASE("custom_callback_logger", "[custom_callback_logger]") {
|
|||||||
spdlog::memory_buf_t formatted;
|
spdlog::memory_buf_t formatted;
|
||||||
formatter.format(msg, formatted);
|
formatter.format(msg, formatted);
|
||||||
auto eol_len = strlen(spdlog::details::os::default_eol);
|
auto eol_len = strlen(spdlog::details::os::default_eol);
|
||||||
using diff_t = typename std::iterator_traits<decltype(formatted.end())>::difference_type;
|
using diff_t =
|
||||||
|
typename std::iterator_traits<decltype(formatted.end())>::difference_type;
|
||||||
lines.emplace_back(formatted.begin(), formatted.end() - static_cast<diff_t>(eol_len));
|
lines.emplace_back(formatted.begin(), formatted.end() - static_cast<diff_t>(eol_len));
|
||||||
});
|
});
|
||||||
std::shared_ptr<spdlog::sinks::test_sink_st> test_sink(new spdlog::sinks::test_sink_st);
|
std::shared_ptr<spdlog::sinks::test_sink_st> test_sink(new spdlog::sinks::test_sink_st);
|
||||||
|
@@ -46,10 +46,8 @@ TEST_CASE("daily_logger with dateonly calculator", "[daily_logger]") {
|
|||||||
|
|
||||||
struct custom_daily_file_name_calculator {
|
struct custom_daily_file_name_calculator {
|
||||||
static spdlog::filename_t calc_filename(const spdlog::filename_t &basename, const tm &now_tm) {
|
static spdlog::filename_t calc_filename(const spdlog::filename_t &basename, const tm &now_tm) {
|
||||||
|
return spdlog::fmt_lib::format(SPDLOG_FILENAME_T("{}{:04d}{:02d}{:02d}"), basename,
|
||||||
return spdlog::fmt_lib::format(SPDLOG_FILENAME_T("{}{:04d}{:02d}{:02d}"),
|
now_tm.tm_year + 1900, now_tm.tm_mon + 1, now_tm.tm_mday);
|
||||||
basename, now_tm.tm_year + 1900, now_tm.tm_mon + 1,
|
|
||||||
now_tm.tm_mday);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -1,12 +1,12 @@
|
|||||||
#ifdef _WIN32 // to prevent fopen warning on windows
|
#ifdef _WIN32 // to prevent fopen warning on windows
|
||||||
#define _CRT_SECURE_NO_WARNINGS
|
#define _CRT_SECURE_NO_WARNINGS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "includes.h"
|
#include "includes.h"
|
||||||
#include "test_sink.h"
|
#include "test_sink.h"
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
std::string log_info(const T &what, spdlog::level::level_enum logger_level = spdlog::level::info) {
|
std::string log_info(const T& what, spdlog::level::level_enum logger_level = spdlog::level::info) {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(oss);
|
auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(oss);
|
||||||
|
|
||||||
@@ -185,14 +185,16 @@ TEST_CASE("utf8 to utf16 conversion using windows api", "[windows utf]") {
|
|||||||
spdlog::details::os::utf8_to_wstrbuf("\xc3\x28", buffer); // Invalid UTF-8 sequence.
|
spdlog::details::os::utf8_to_wstrbuf("\xc3\x28", buffer); // Invalid UTF-8 sequence.
|
||||||
REQUIRE(std::wstring(buffer.data(), buffer.size()) == std::wstring(L"\xfffd("));
|
REQUIRE(std::wstring(buffer.data(), buffer.size()) == std::wstring(L"\xfffd("));
|
||||||
|
|
||||||
spdlog::details::os::utf8_to_wstrbuf("\xe3\x81\xad\xe3\x81\x93", buffer); // "Neko" in hiragana.
|
spdlog::details::os::utf8_to_wstrbuf("\xe3\x81\xad\xe3\x81\x93",
|
||||||
|
buffer); // "Neko" in hiragana.
|
||||||
REQUIRE(std::wstring(buffer.data(), buffer.size()) == std::wstring(L"\x306d\x3053"));
|
REQUIRE(std::wstring(buffer.data(), buffer.size()) == std::wstring(L"\x306d\x3053"));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct auto_closer {
|
struct auto_closer {
|
||||||
FILE* fp = nullptr;
|
FILE* fp = nullptr;
|
||||||
explicit auto_closer(FILE* f) : fp(f) {}
|
explicit auto_closer(FILE* f)
|
||||||
|
: fp(f) {}
|
||||||
auto_closer(const auto_closer&) = delete;
|
auto_closer(const auto_closer&) = delete;
|
||||||
auto_closer& operator=(const auto_closer&) = delete;
|
auto_closer& operator=(const auto_closer&) = delete;
|
||||||
~auto_closer() {
|
~auto_closer() {
|
||||||
@@ -201,10 +203,10 @@ struct auto_closer {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TEST_CASE("os::fwrite_bytes", "[os]") {
|
TEST_CASE("os::fwrite_bytes", "[os]") {
|
||||||
using spdlog::details::os::fwrite_bytes;
|
|
||||||
using spdlog::details::os::create_dir;
|
using spdlog::details::os::create_dir;
|
||||||
|
using spdlog::details::os::fwrite_bytes;
|
||||||
const char* filename = "log_tests/test_fwrite_bytes.txt";
|
const char* filename = "log_tests/test_fwrite_bytes.txt";
|
||||||
const char *msg = "hello";
|
const char* msg = "hello";
|
||||||
prepare_logdir();
|
prepare_logdir();
|
||||||
REQUIRE(create_dir(SPDLOG_FILENAME_T("log_tests")) == true);
|
REQUIRE(create_dir(SPDLOG_FILENAME_T("log_tests")) == true);
|
||||||
{
|
{
|
||||||
|
@@ -23,7 +23,9 @@ static std::string log_to_str(const std::string &msg, const Args &...args) {
|
|||||||
|
|
||||||
// log to str and return it with time
|
// log to str and return it with time
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
static std::string log_to_str_with_time(spdlog::log_clock::time_point log_time, const std::string &msg, const Args &...args) {
|
static std::string log_to_str_with_time(spdlog::log_clock::time_point log_time,
|
||||||
|
const std::string &msg,
|
||||||
|
const Args &...args) {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(oss);
|
auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(oss);
|
||||||
spdlog::logger oss_logger("pattern_tester", oss_sink);
|
spdlog::logger oss_logger("pattern_tester", oss_sink);
|
||||||
@@ -80,8 +82,8 @@ TEST_CASE("GMT offset ", "[pattern_formatter]") {
|
|||||||
const auto now = std::chrono::system_clock::now();
|
const auto now = std::chrono::system_clock::now();
|
||||||
const auto yesterday = now - 24h;
|
const auto yesterday = now - 24h;
|
||||||
|
|
||||||
REQUIRE(log_to_str_with_time(yesterday, "Some message", "%z", spdlog::pattern_time_type::utc, "\n") ==
|
REQUIRE(log_to_str_with_time(yesterday, "Some message", "%z", spdlog::pattern_time_type::utc,
|
||||||
"+00:00\n");
|
"\n") == "+00:00\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("color range test1", "[pattern_formatter]") {
|
TEST_CASE("color range test1", "[pattern_formatter]") {
|
||||||
|
Reference in New Issue
Block a user