clang-format

This commit is contained in:
gabime 2021-07-19 00:50:51 +03:00
parent e98265a49b
commit e7e8b75a4c
75 changed files with 655 additions and 654 deletions

View File

@ -18,47 +18,47 @@ include(GNUInstallDirs)
# --------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------
# Set CMake policies to support later version behaviour # Set CMake policies to support later version behaviour
# --------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------
if (POLICY CMP0077) if(POLICY CMP0077)
cmake_policy(SET CMP0077 NEW) # option() honors variables already set cmake_policy(SET CMP0077 NEW) # option() honors variables already set
endif () endif()
# --------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------
# Set default build to release # Set default build to release
# --------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------
if (NOT CMAKE_BUILD_TYPE) if(NOT CMAKE_BUILD_TYPE)
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 (NOT CMAKE_CXX_STANDARD) if(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()
# make sure __cplusplus is defined when using msvc # make sure __cplusplus is defined when using msvc
if (MSVC) if(MSVC)
string(APPEND CMAKE_CXX_FLAGS " /Zc:__cplusplus") string(APPEND CMAKE_CXX_FLAGS " /Zc:__cplusplus")
endif () endif()
set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_EXTENSIONS OFF)
if (CMAKE_SYSTEM_NAME MATCHES "CYGWIN" OR CMAKE_SYSTEM_NAME MATCHES "MSYS") if(CMAKE_SYSTEM_NAME MATCHES "CYGWIN" OR CMAKE_SYSTEM_NAME MATCHES "MSYS")
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)
@ -91,44 +91,44 @@ 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()
# 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)
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)
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)
option(SPDLOG_NO_TLS "prevent spdlog from using thread local storage" OFF) option(SPDLOG_NO_TLS "prevent spdlog from using thread local storage" OFF)
option( option(
SPDLOG_NO_ATOMIC_LEVELS SPDLOG_NO_ATOMIC_LEVELS
"prevent spdlog from using of std::atomic log levels (use only if your code never modifies log levels concurrently" "prevent spdlog from using of std::atomic log levels (use only if your code never modifies log levels concurrently"
OFF) OFF)
option(SPDLOG_DISABLE_DEFAULT_LOGGER "Disable default logger creation" OFF) option(SPDLOG_DISABLE_DEFAULT_LOGGER "Disable default logger creation" OFF)
# clang-tidy # clang-tidy
if (${CMAKE_VERSION} VERSION_GREATER "3.5") if(${CMAKE_VERSION} VERSION_GREATER "3.5")
option(SPDLOG_TIDY "run clang-tidy" OFF) option(SPDLOG_TIDY "run clang-tidy" OFF)
endif () endif()
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()
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
message(STATUS "Build type: " ${CMAKE_BUILD_TYPE}) message(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
@ -137,43 +137,43 @@ 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_FMT_EXTERNAL AND NOT SPDLOG_FMT_EXTERNAL_HO) if(NOT SPDLOG_FMT_EXTERNAL AND NOT SPDLOG_FMT_EXTERNAL_HO)
list(APPEND SPDLOG_SRCS src/fmt.cpp) list(APPEND SPDLOG_SRCS src/fmt.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 (MSVC) if(MSVC)
target_compile_options(spdlog PUBLIC target_compile_options(spdlog PUBLIC $<$<AND:$<CXX_COMPILER_ID:MSVC>,$<NOT:$<COMPILE_LANGUAGE:CUDA>>>:/wd4251
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<NOT:$<COMPILE_LANGUAGE:CUDA>>>:/wd4251 /wd4275>) /wd4275>)
endif () endif()
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 PRIVATE FMT_EXPORT PUBLIC FMT_SHARED) target_compile_definitions(spdlog PRIVATE FMT_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)
target_compile_definitions(spdlog PUBLIC SPDLOG_COMPILED_LIB) target_compile_definitions(spdlog PUBLIC SPDLOG_COMPILED_LIB)
target_include_directories(spdlog PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>" target_include_directories(spdlog PUBLIC "$<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)
spdlog_enable_warnings(spdlog) spdlog_enable_warnings(spdlog)
set_target_properties(spdlog PROPERTIES VERSION ${SPDLOG_VERSION} SOVERSION ${SPDLOG_VERSION_MAJOR}) set_target_properties(spdlog PROPERTIES VERSION ${SPDLOG_VERSION} SOVERSION ${SPDLOG_VERSION_MAJOR})
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()
# --------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------
# Header only version # Header only version
@ -182,92 +182,91 @@ add_library(spdlog_header_only INTERFACE)
add_library(spdlog::spdlog_header_only ALIAS spdlog_header_only) add_library(spdlog::spdlog_header_only ALIAS spdlog_header_only)
target_include_directories(spdlog_header_only INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>" target_include_directories(spdlog_header_only INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>") "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
target_link_libraries(spdlog_header_only INTERFACE Threads::Threads) 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-nly # use external fmt-header-nly
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()
# --------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------
# 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})
foreach ( foreach(
SPDLOG_OPTION SPDLOG_OPTION
SPDLOG_WCHAR_TO_UTF8_SUPPORT SPDLOG_WCHAR_TO_UTF8_SUPPORT
SPDLOG_WCHAR_FILENAMES SPDLOG_WCHAR_FILENAMES
SPDLOG_NO_EXCEPTIONS SPDLOG_NO_EXCEPTIONS
SPDLOG_CLOCK_COARSE SPDLOG_CLOCK_COARSE
SPDLOG_PREVENT_CHILD_FD SPDLOG_PREVENT_CHILD_FD
SPDLOG_NO_THREAD_ID SPDLOG_NO_THREAD_ID
SPDLOG_NO_TLS SPDLOG_NO_TLS
SPDLOG_NO_ATOMIC_LEVELS SPDLOG_NO_ATOMIC_LEVELS
SPDLOG_DISABLE_DEFAULT_LOGGER) SPDLOG_DISABLE_DEFAULT_LOGGER)
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 (SPDLOG_NO_EXCEPTIONS AND NOT MSVC) if(SPDLOG_NO_EXCEPTIONS AND NOT MSVC)
target_compile_options(spdlog PRIVATE -fno-exceptions) target_compile_options(spdlog PRIVATE -fno-exceptions)
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")
@ -282,16 +281,16 @@ if (SPDLOG_INSTALL)
# --------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------
install(DIRECTORY include/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" PATTERN "fmt/bundled" EXCLUDE) install(DIRECTORY include/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" PATTERN "fmt/bundled" EXCLUDE)
install( install(
TARGETS spdlog spdlog_header_only TARGETS spdlog spdlog_header_only
EXPORT spdlog EXPORT spdlog
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
if (NOT SPDLOG_FMT_EXTERNAL AND NOT SPDLOG_FMT_EXTERNAL_HO) if(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
@ -317,5 +316,4 @@ if (SPDLOG_INSTALL)
# Support creation of installable packages # Support creation of installable packages
# --------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------
include(cmake/spdlogCPack.cmake) include(cmake/spdlogCPack.cmake)
endif () endif()

View File

@ -10,17 +10,15 @@ endif()
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
find_package(benchmark CONFIG) find_package(benchmark CONFIG)
if (NOT benchmark_FOUND) if(NOT benchmark_FOUND)
message(STATUS "Using CMake Version ${CMAKE_VERSION}") message(STATUS "Using CMake Version ${CMAKE_VERSION}")
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.11.0") if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.11.0")
# User can fetch googlebenchmark # User can fetch googlebenchmark
message(STATUS "Downloading GoogleBenchmark") message(STATUS "Downloading GoogleBenchmark")
include(FetchContent) include(FetchContent)
set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE INTERNAL "") set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE INTERNAL "")
# Do not build and run googlebenchmark tests # Do not build and run googlebenchmark tests
FetchContent_Declare(googlebenchmark FetchContent_Declare(googlebenchmark GIT_REPOSITORY https://github.com/google/benchmark.git GIT_TAG v1.5.2)
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG v1.5.2)
FetchContent_MakeAvailable(googlebenchmark) FetchContent_MakeAvailable(googlebenchmark)
else() else()

View File

@ -2,21 +2,21 @@
function(spdlog_extract_version) function(spdlog_extract_version)
file(READ "${CMAKE_CURRENT_LIST_DIR}/include/spdlog/version.h" file_contents) file(READ "${CMAKE_CURRENT_LIST_DIR}/include/spdlog/version.h" file_contents)
string(REGEX MATCH "SPDLOG_VER_MAJOR ([0-9]+)" _ "${file_contents}") string(REGEX MATCH "SPDLOG_VER_MAJOR ([0-9]+)" _ "${file_contents}")
if (NOT CMAKE_MATCH_COUNT EQUAL 1) if(NOT CMAKE_MATCH_COUNT EQUAL 1)
message(FATAL_ERROR "Could not extract major version number from spdlog/version.h") message(FATAL_ERROR "Could not extract major version number from spdlog/version.h")
endif () endif()
set(ver_major ${CMAKE_MATCH_1}) set(ver_major ${CMAKE_MATCH_1})
string(REGEX MATCH "SPDLOG_VER_MINOR ([0-9]+)" _ "${file_contents}") string(REGEX MATCH "SPDLOG_VER_MINOR ([0-9]+)" _ "${file_contents}")
if (NOT CMAKE_MATCH_COUNT EQUAL 1) if(NOT CMAKE_MATCH_COUNT EQUAL 1)
message(FATAL_ERROR "Could not extract minor version number from spdlog/version.h") message(FATAL_ERROR "Could not extract minor version number from spdlog/version.h")
endif () endif()
set(ver_minor ${CMAKE_MATCH_1}) set(ver_minor ${CMAKE_MATCH_1})
string(REGEX MATCH "SPDLOG_VER_PATCH ([0-9]+)" _ "${file_contents}") string(REGEX MATCH "SPDLOG_VER_PATCH ([0-9]+)" _ "${file_contents}")
if (NOT CMAKE_MATCH_COUNT EQUAL 1) if(NOT CMAKE_MATCH_COUNT EQUAL 1)
message(FATAL_ERROR "Could not extract patch version number from spdlog/version.h") message(FATAL_ERROR "Could not extract patch version number from spdlog/version.h")
endif () endif()
set(ver_patch ${CMAKE_MATCH_1}) set(ver_patch ${CMAKE_MATCH_1})
set(SPDLOG_VERSION_MAJOR ${ver_major} PARENT_SCOPE) set(SPDLOG_VERSION_MAJOR ${ver_major} PARENT_SCOPE)
@ -27,32 +27,32 @@ endfunction()
# Turn on warnings on the given target # Turn on warnings on the given target
function(spdlog_enable_warnings target_name) function(spdlog_enable_warnings target_name)
if (SPDLOG_BUILD_WARNINGS) if(SPDLOG_BUILD_WARNINGS)
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
list(APPEND MSVC_OPTIONS "/W3") list(APPEND MSVC_OPTIONS "/W3")
if (MSVC_VERSION GREATER 1900) # Allow non fatal security warnings for msvc 2015 if(MSVC_VERSION GREATER 1900) # Allow non fatal security warnings for msvc 2015
list(APPEND MSVC_OPTIONS "/WX") list(APPEND MSVC_OPTIONS "/WX")
endif () endif()
endif () endif()
target_compile_options( target_compile_options(
${target_name} ${target_name}
PRIVATE $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>: PRIVATE $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-Wall -Wall
-Wextra -Wextra
-Wconversion -Wconversion
-pedantic -pedantic
-Werror -Werror
-Wfatal-errors> -Wfatal-errors>
$<$<CXX_COMPILER_ID:MSVC>:${MSVC_OPTIONS}>) $<$<CXX_COMPILER_ID:MSVC>:${MSVC_OPTIONS}>)
endif () endif()
endfunction() endfunction()
# Enable address sanitizer (gcc/clang only) # Enable address sanitizer (gcc/clang only)
function(spdlog_enable_sanitizer target_name) function(spdlog_enable_sanitizer target_name)
if (NOT CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") if(NOT CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
message(FATAL_ERROR "Sanitizer supported only for gcc/clang") message(FATAL_ERROR "Sanitizer supported only for gcc/clang")
endif () endif()
message(STATUS "Address sanitizer enabled") message(STATUS "Address sanitizer enabled")
target_compile_options(${target_name} PRIVATE -fsanitize=address,undefined) target_compile_options(${target_name} PRIVATE -fsanitize=address,undefined)
target_compile_options(${target_name} PRIVATE -fno-sanitize=signed-integer-overflow) target_compile_options(${target_name} PRIVATE -fno-sanitize=signed-integer-overflow)
@ -60,4 +60,3 @@ function(spdlog_enable_sanitizer target_name)
target_compile_options(${target_name} PRIVATE -fno-omit-frame-pointer) target_compile_options(${target_name} PRIVATE -fno-omit-frame-pointer)
target_link_libraries(${target_name} PRIVATE -fsanitize=address,undefined -fuse-ld=gold) target_link_libraries(${target_name} PRIVATE -fsanitize=address,undefined -fuse-ld=gold)
endfunction() endfunction()

View File

@ -246,7 +246,7 @@ void err_handler_example()
// syslog example (linux/osx/freebsd) // syslog example (linux/osx/freebsd)
#ifndef _WIN32 #ifndef _WIN32
#include "spdlog/sinks/syslog_sink.h" # include "spdlog/sinks/syslog_sink.h"
void syslog_example() void syslog_example()
{ {
std::string ident = "spdlog-example"; std::string ident = "spdlog-example";
@ -257,7 +257,7 @@ void syslog_example()
// Android example. // Android example.
#if defined(__ANDROID__) #if defined(__ANDROID__)
#include "spdlog/sinks/android_sink.h" # include "spdlog/sinks/android_sink.h"
void android_example() void android_example()
{ {
std::string tag = "spdlog-android"; std::string tag = "spdlog-android";

View File

@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/async_logger.h> # include <spdlog/async_logger.h>
#endif #endif
#include <spdlog/sinks/sink.h> #include <spdlog/sinks/sink.h>

View File

@ -64,5 +64,5 @@ private:
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "async_logger-inl.h" # include "async_logger-inl.h"
#endif #endif

View File

@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/cfg/helpers.h> # include <spdlog/cfg/helpers.h>
#endif #endif
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>

View File

@ -25,5 +25,5 @@ SPDLOG_API void load_levels(const std::string &txt);
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "helpers-inl.h" # include "helpers-inl.h"
#endif // SPDLOG_HEADER_ONLY #endif // SPDLOG_HEADER_ONLY

View File

@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/common.h> # include <spdlog/common.h>
#endif #endif
#include <algorithm> #include <algorithm>
@ -16,7 +16,7 @@ namespace level {
#if __cplusplus >= 201703L #if __cplusplus >= 201703L
constexpr constexpr
#endif #endif
static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES; static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES;
static const char *short_level_names[] SPDLOG_SHORT_LEVEL_NAMES; static const char *short_level_names[] SPDLOG_SHORT_LEVEL_NAMES;

View File

@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/details/backtracer.h> # include <spdlog/details/backtracer.h>
#endif #endif
namespace spdlog { namespace spdlog {
namespace details { namespace details {

View File

@ -41,6 +41,5 @@ public:
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "backtracer-inl.h" # include "backtracer-inl.h"
#endif #endif

View File

@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/details/file_helper.h> # include <spdlog/details/file_helper.h>
#endif #endif
#include <spdlog/details/os.h> #include <spdlog/details/os.h>

View File

@ -55,5 +55,5 @@ private:
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "file_helper-inl.h" # include "file_helper-inl.h"
#endif #endif

View File

@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/details/log_msg.h> # include <spdlog/details/log_msg.h>
#endif #endif
#include <spdlog/details/os.h> #include <spdlog/details/os.h>

View File

@ -33,5 +33,5 @@ struct SPDLOG_API log_msg
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "log_msg-inl.h" # include "log_msg-inl.h"
#endif #endif

View File

@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/details/log_msg_buffer.h> # include <spdlog/details/log_msg_buffer.h>
#endif #endif
namespace spdlog { namespace spdlog {
@ -26,9 +26,7 @@ SPDLOG_INLINE log_msg_buffer::log_msg_buffer(const log_msg_buffer &other)
update_string_views(); update_string_views();
} }
SPDLOG_INLINE log_msg_buffer::log_msg_buffer(log_msg_buffer &&other) SPDLOG_NOEXCEPT SPDLOG_INLINE log_msg_buffer::log_msg_buffer(log_msg_buffer &&other) SPDLOG_NOEXCEPT : log_msg{other}, buffer{std::move(other.buffer)}
: log_msg{other}
, buffer{std::move(other.buffer)}
{ {
update_string_views(); update_string_views();
} }

View File

@ -29,5 +29,5 @@ public:
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "log_msg_buffer-inl.h" # include "log_msg_buffer-inl.h"
#endif #endif

View File

@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/details/os.h> # include <spdlog/details/os.h>
#endif #endif
#include <spdlog/common.h> #include <spdlog/common.h>
@ -23,45 +23,45 @@
#ifdef _WIN32 #ifdef _WIN32
#include <io.h> // _get_osfhandle and _isatty support # include <io.h> // _get_osfhandle and _isatty support
#include <process.h> // _get_pid support # include <process.h> // _get_pid support
#include <spdlog/details/windows_include.h> # include <spdlog/details/windows_include.h>
#ifdef __MINGW32__ # ifdef __MINGW32__
#include <share.h> # include <share.h>
#endif # endif
#if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES) # if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)
#include <limits> # include <limits>
#endif # endif
#include <direct.h> // for _mkdir/_wmkdir # include <direct.h> // for _mkdir/_wmkdir
#else // unix #else // unix
#include <fcntl.h> # include <fcntl.h>
#include <unistd.h> # include <unistd.h>
#ifdef __linux__ # ifdef __linux__
#include <sys/syscall.h> //Use gettid() syscall under linux to get thread id # include <sys/syscall.h> //Use gettid() syscall under linux to get thread id
#elif defined(_AIX) # elif defined(_AIX)
#include <pthread.h> // for pthread_getthreadid_np # include <pthread.h> // for pthread_getthreadid_np
#elif defined(__DragonFly__) || defined(__FreeBSD__) # elif defined(__DragonFly__) || defined(__FreeBSD__)
#include <pthread_np.h> // for pthread_getthreadid_np # include <pthread_np.h> // for pthread_getthreadid_np
#elif defined(__NetBSD__) # elif defined(__NetBSD__)
#include <lwp.h> // for _lwp_self # include <lwp.h> // for _lwp_self
#elif defined(__sun) # elif defined(__sun)
#include <thread.h> // for thr_self # include <thread.h> // for thr_self
#endif # endif
#endif // unix #endif // unix
#ifndef __has_feature // Clang - feature checking macros. #ifndef __has_feature // Clang - feature checking macros.
#define __has_feature(x) 0 // Compatibility with non-clang compilers. # define __has_feature(x) 0 // Compatibility with non-clang compilers.
#endif #endif
namespace spdlog { namespace spdlog {
@ -123,12 +123,12 @@ SPDLOG_INLINE std::tm gmtime() SPDLOG_NOEXCEPT
SPDLOG_INLINE bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode) SPDLOG_INLINE bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode)
{ {
#ifdef _WIN32 #ifdef _WIN32
#ifdef SPDLOG_WCHAR_FILENAMES # ifdef SPDLOG_WCHAR_FILENAMES
*fp = ::_wfsopen((filename.c_str()), mode.c_str(), _SH_DENYNO); *fp = ::_wfsopen((filename.c_str()), mode.c_str(), _SH_DENYNO);
#else # else
*fp = ::_fsopen((filename.c_str()), mode.c_str(), _SH_DENYNO); *fp = ::_fsopen((filename.c_str()), mode.c_str(), _SH_DENYNO);
#endif # endif
#if defined(SPDLOG_PREVENT_CHILD_FD) # if defined(SPDLOG_PREVENT_CHILD_FD)
if (*fp != nullptr) if (*fp != nullptr)
{ {
auto file_handle = reinterpret_cast<HANDLE>(_get_osfhandle(::_fileno(*fp))); auto file_handle = reinterpret_cast<HANDLE>(_get_osfhandle(::_fileno(*fp)));
@ -138,9 +138,9 @@ SPDLOG_INLINE bool fopen_s(FILE **fp, const filename_t &filename, const filename
*fp = nullptr; *fp = nullptr;
} }
} }
#endif # endif
#else // unix #else // unix
#if defined(SPDLOG_PREVENT_CHILD_FD) # if defined(SPDLOG_PREVENT_CHILD_FD)
const int mode_flag = mode == SPDLOG_FILENAME_T("ab") ? O_APPEND : O_TRUNC; const int mode_flag = mode == SPDLOG_FILENAME_T("ab") ? O_APPEND : O_TRUNC;
const int fd = ::open((filename.c_str()), O_CREAT | O_WRONLY | O_CLOEXEC | mode_flag, mode_t(0644)); const int fd = ::open((filename.c_str()), O_CREAT | O_WRONLY | O_CLOEXEC | mode_flag, mode_t(0644));
if (fd == -1) if (fd == -1)
@ -152,9 +152,9 @@ SPDLOG_INLINE bool fopen_s(FILE **fp, const filename_t &filename, const filename
{ {
::close(fd); ::close(fd);
} }
#else # else
*fp = ::fopen((filename.c_str()), mode.c_str()); *fp = ::fopen((filename.c_str()), mode.c_str());
#endif # endif
#endif #endif
return *fp == nullptr; return *fp == nullptr;
@ -187,11 +187,11 @@ SPDLOG_INLINE int rename(const filename_t &filename1, const filename_t &filename
SPDLOG_INLINE bool path_exists(const filename_t &filename) SPDLOG_NOEXCEPT SPDLOG_INLINE bool path_exists(const filename_t &filename) SPDLOG_NOEXCEPT
{ {
#ifdef _WIN32 #ifdef _WIN32
#ifdef SPDLOG_WCHAR_FILENAMES # ifdef SPDLOG_WCHAR_FILENAMES
auto attribs = ::GetFileAttributesW(filename.c_str()); auto attribs = ::GetFileAttributesW(filename.c_str());
#else # else
auto attribs = ::GetFileAttributesA(filename.c_str()); auto attribs = ::GetFileAttributesA(filename.c_str());
#endif # endif
return attribs != INVALID_FILE_ATTRIBUTES; return attribs != INVALID_FILE_ATTRIBUTES;
#else // common linux/unix all have the stat system call #else // common linux/unix all have the stat system call
struct stat buffer; struct stat buffer;
@ -200,9 +200,9 @@ SPDLOG_INLINE bool path_exists(const filename_t &filename) SPDLOG_NOEXCEPT
} }
#ifdef _MSC_VER #ifdef _MSC_VER
// avoid warning about unreachable statement at the end of filesize() // avoid warning about unreachable statement at the end of filesize()
#pragma warning(push) # pragma warning(push)
#pragma warning(disable: 4702) # pragma warning(disable : 4702)
#endif #endif
// Return file size according to open FILE* object // Return file size according to open FILE* object
@ -214,49 +214,49 @@ SPDLOG_INLINE size_t filesize(FILE *f)
} }
#if defined(_WIN32) && !defined(__CYGWIN__) #if defined(_WIN32) && !defined(__CYGWIN__)
int fd = ::_fileno(f); int fd = ::_fileno(f);
#if defined(_WIN64) // 64 bits # if defined(_WIN64) // 64 bits
__int64 ret = ::_filelengthi64(fd); __int64 ret = ::_filelengthi64(fd);
if (ret >= 0) if (ret >= 0)
{ {
return static_cast<size_t>(ret); return static_cast<size_t>(ret);
} }
#else // windows 32 bits # else // windows 32 bits
long ret = ::_filelength(fd); long ret = ::_filelength(fd);
if (ret >= 0) if (ret >= 0)
{ {
return static_cast<size_t>(ret); return static_cast<size_t>(ret);
} }
#endif # endif
#else // unix #else // unix
// OpenBSD doesn't compile with :: before the fileno(..) // OpenBSD doesn't compile with :: before the fileno(..)
#if defined(__OpenBSD__) # if defined(__OpenBSD__)
int fd = fileno(f); int fd = fileno(f);
#else # else
int fd = ::fileno(f); int fd = ::fileno(f);
#endif # endif
// 64 bits(but not in osx or cygwin, where fstat64 is deprecated) // 64 bits(but not in osx or cygwin, where fstat64 is deprecated)
#if (defined(__linux__) || defined(__sun) || defined(_AIX)) && (defined(__LP64__) || defined(_LP64)) # if (defined(__linux__) || defined(__sun) || defined(_AIX)) && (defined(__LP64__) || defined(_LP64))
struct stat64 st; struct stat64 st;
if (::fstat64(fd, &st) == 0) if (::fstat64(fd, &st) == 0)
{ {
return static_cast<size_t>(st.st_size); return static_cast<size_t>(st.st_size);
} }
#else // other unix or linux 32 bits or cygwin # else // other unix or linux 32 bits or cygwin
struct stat st; struct stat st;
if (::fstat(fd, &st) == 0) if (::fstat(fd, &st) == 0)
{ {
return static_cast<size_t>(st.st_size); return static_cast<size_t>(st.st_size);
} }
#endif # endif
#endif #endif
throw_spdlog_ex("Failed getting file size from fd", errno); throw_spdlog_ex("Failed getting file size from fd", errno);
return 0; // will not be reached. return 0; // will not be reached.
} }
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) # pragma warning(pop)
#endif #endif
// Return utc offset in minutes or throw spdlog_ex on failure // Return utc offset in minutes or throw spdlog_ex on failure
@ -264,13 +264,13 @@ SPDLOG_INLINE int utc_minutes_offset(const std::tm &tm)
{ {
#ifdef _WIN32 #ifdef _WIN32
#if _WIN32_WINNT < _WIN32_WINNT_WS08 # if _WIN32_WINNT < _WIN32_WINNT_WS08
TIME_ZONE_INFORMATION tzinfo; TIME_ZONE_INFORMATION tzinfo;
auto rv = ::GetTimeZoneInformation(&tzinfo); auto rv = ::GetTimeZoneInformation(&tzinfo);
#else # else
DYNAMIC_TIME_ZONE_INFORMATION tzinfo; DYNAMIC_TIME_ZONE_INFORMATION tzinfo;
auto rv = ::GetDynamicTimeZoneInformation(&tzinfo); auto rv = ::GetDynamicTimeZoneInformation(&tzinfo);
#endif # endif
if (rv == TIME_ZONE_ID_INVALID) if (rv == TIME_ZONE_ID_INVALID)
throw_spdlog_ex("Failed getting timezone info. ", errno); throw_spdlog_ex("Failed getting timezone info. ", errno);
@ -286,7 +286,7 @@ SPDLOG_INLINE int utc_minutes_offset(const std::tm &tm)
return offset; return offset;
#else #else
#if defined(sun) || defined(__sun) || defined(_AIX) || (!defined(_BSD_SOURCE) && !defined(_GNU_SOURCE)) # if defined(sun) || defined(__sun) || defined(_AIX) || (!defined(_BSD_SOURCE) && !defined(_GNU_SOURCE))
// 'tm_gmtoff' field is BSD extension and it's missing on SunOS/Solaris // 'tm_gmtoff' field is BSD extension and it's missing on SunOS/Solaris
struct helper struct helper
{ {
@ -316,9 +316,9 @@ SPDLOG_INLINE int utc_minutes_offset(const std::tm &tm)
}; };
auto offset_seconds = helper::calculate_gmt_offset(tm); auto offset_seconds = helper::calculate_gmt_offset(tm);
#else # else
auto offset_seconds = tm.tm_gmtoff; auto offset_seconds = tm.tm_gmtoff;
#endif # endif
return static_cast<int>(offset_seconds / 60); return static_cast<int>(offset_seconds / 60);
#endif #endif
@ -332,9 +332,9 @@ SPDLOG_INLINE size_t _thread_id() SPDLOG_NOEXCEPT
#ifdef _WIN32 #ifdef _WIN32
return static_cast<size_t>(::GetCurrentThreadId()); return static_cast<size_t>(::GetCurrentThreadId());
#elif defined(__linux__) #elif defined(__linux__)
#if defined(__ANDROID__) && defined(__ANDROID_API__) && (__ANDROID_API__ < 21) # if defined(__ANDROID__) && defined(__ANDROID_API__) && (__ANDROID_API__ < 21)
#define SYS_gettid __NR_gettid # define SYS_gettid __NR_gettid
#endif # endif
return static_cast<size_t>(::syscall(SYS_gettid)); return static_cast<size_t>(::syscall(SYS_gettid));
#elif defined(_AIX) || defined(__DragonFly__) || defined(__FreeBSD__) #elif defined(_AIX) || defined(__DragonFly__) || defined(__FreeBSD__)
return static_cast<size_t>(::pthread_getthreadid_np()); return static_cast<size_t>(::pthread_getthreadid_np());
@ -519,11 +519,11 @@ SPDLOG_INLINE void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target)
static SPDLOG_INLINE bool mkdir_(const filename_t &path) static SPDLOG_INLINE bool mkdir_(const filename_t &path)
{ {
#ifdef _WIN32 #ifdef _WIN32
#ifdef SPDLOG_WCHAR_FILENAMES # ifdef SPDLOG_WCHAR_FILENAMES
return ::_wmkdir(path.c_str()) == 0; return ::_wmkdir(path.c_str()) == 0;
#else # else
return ::_mkdir(path.c_str()) == 0; return ::_mkdir(path.c_str()) == 0;
#endif # endif
#else #else
return ::mkdir(path.c_str(), mode_t(0755)) == 0; return ::mkdir(path.c_str(), mode_t(0755)) == 0;
#endif #endif
@ -580,14 +580,14 @@ std::string SPDLOG_INLINE getenv(const char *field)
{ {
#if defined(_MSC_VER) #if defined(_MSC_VER)
#if defined(__cplusplus_winrt) # if defined(__cplusplus_winrt)
return std::string{}; // not supported under uwp return std::string{}; // not supported under uwp
#else # else
size_t len = 0; size_t len = 0;
char buf[128]; char buf[128];
bool ok = ::getenv_s(&len, buf, sizeof(buf), field) == 0; bool ok = ::getenv_s(&len, buf, sizeof(buf), field) == 0;
return ok ? buf : std::string{}; return ok ? buf : std::string{};
#endif # endif
#else // revert to getenv #else // revert to getenv
char *buf = ::getenv(field); char *buf = ::getenv(field);
return buf ? buf : std::string{}; return buf ? buf : std::string{};

View File

@ -22,22 +22,22 @@ SPDLOG_API std::tm gmtime() SPDLOG_NOEXCEPT;
// eol definition // eol definition
#if !defined(SPDLOG_EOL) #if !defined(SPDLOG_EOL)
#ifdef _WIN32 # ifdef _WIN32
#define SPDLOG_EOL "\r\n" # define SPDLOG_EOL "\r\n"
#else # else
#define SPDLOG_EOL "\n" # define SPDLOG_EOL "\n"
#endif # endif
#endif #endif
SPDLOG_CONSTEXPR static const char *default_eol = SPDLOG_EOL; SPDLOG_CONSTEXPR static const char *default_eol = SPDLOG_EOL;
// folder separator // folder separator
#if !defined(SPDLOG_FOLDER_SEPS) #if !defined(SPDLOG_FOLDER_SEPS)
#ifdef _WIN32 # ifdef _WIN32
#define SPDLOG_FOLDER_SEPS "\\/" # define SPDLOG_FOLDER_SEPS "\\/"
#else # else
#define SPDLOG_FOLDER_SEPS "/" # define SPDLOG_FOLDER_SEPS "/"
#endif # endif
#endif #endif
SPDLOG_CONSTEXPR static const char folder_seps[] = SPDLOG_FOLDER_SEPS; SPDLOG_CONSTEXPR static const char folder_seps[] = SPDLOG_FOLDER_SEPS;
@ -114,5 +114,5 @@ SPDLOG_API std::string getenv(const char *field);
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "os-inl.h" # include "os-inl.h"
#endif #endif

View File

@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/details/periodic_worker.h> # include <spdlog/details/periodic_worker.h>
#endif #endif
namespace spdlog { namespace spdlog {

View File

@ -36,5 +36,5 @@ private:
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "periodic_worker-inl.h" # include "periodic_worker-inl.h"
#endif #endif

View File

@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/details/registry.h> # include <spdlog/details/registry.h>
#endif #endif
#include <spdlog/common.h> #include <spdlog/common.h>
@ -14,11 +14,11 @@
#ifndef SPDLOG_DISABLE_DEFAULT_LOGGER #ifndef SPDLOG_DISABLE_DEFAULT_LOGGER
// support for the default stdout color logger // support for the default stdout color logger
#ifdef _WIN32 # ifdef _WIN32
#include <spdlog/sinks/wincolor_sink.h> # include <spdlog/sinks/wincolor_sink.h>
#else # else
#include <spdlog/sinks/ansicolor_sink.h> # include <spdlog/sinks/ansicolor_sink.h>
#endif # endif
#endif // SPDLOG_DISABLE_DEFAULT_LOGGER #endif // SPDLOG_DISABLE_DEFAULT_LOGGER
#include <chrono> #include <chrono>
@ -36,11 +36,11 @@ SPDLOG_INLINE registry::registry()
#ifndef SPDLOG_DISABLE_DEFAULT_LOGGER #ifndef SPDLOG_DISABLE_DEFAULT_LOGGER
// create default logger (ansicolor_stdout_sink_mt or wincolor_stdout_sink_mt in windows). // create default logger (ansicolor_stdout_sink_mt or wincolor_stdout_sink_mt in windows).
#ifdef _WIN32 # ifdef _WIN32
auto color_sink = std::make_shared<sinks::wincolor_stdout_sink_mt>(); auto color_sink = std::make_shared<sinks::wincolor_stdout_sink_mt>();
#else # else
auto color_sink = std::make_shared<sinks::ansicolor_stdout_sink_mt>(); auto color_sink = std::make_shared<sinks::ansicolor_stdout_sink_mt>();
#endif # endif
const char *default_logger_name = ""; const char *default_logger_name = "";
default_logger_ = std::make_shared<spdlog::logger>(default_logger_name, std::move(color_sink)); default_logger_ = std::make_shared<spdlog::logger>(default_logger_name, std::move(color_sink));

View File

@ -111,5 +111,5 @@ private:
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "registry-inl.h" # include "registry-inl.h"
#endif #endif

View File

@ -22,4 +22,3 @@ struct synchronous_factory
} }
}; };
} // namespace spdlog } // namespace spdlog

View File

@ -4,7 +4,7 @@
#pragma once #pragma once
#ifdef _WIN32 #ifdef _WIN32
#error include tcp_client-windows.h instead # error include tcp_client-windows.h instead
#endif #endif
// tcp client helper // tcp client helper
@ -111,7 +111,7 @@ public:
#endif #endif
#if !defined(SO_NOSIGPIPE) && !defined(MSG_NOSIGNAL) #if !defined(SO_NOSIGPIPE) && !defined(MSG_NOSIGNAL)
#error "tcp_sink would raise SIGPIPE since niether SO_NOSIGPIPE nor MSG_NOSIGNAL are available" # error "tcp_sink would raise SIGPIPE since niether SO_NOSIGPIPE nor MSG_NOSIGNAL are available"
#endif #endif
} }

View File

@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/details/thread_pool.h> # include <spdlog/details/thread_pool.h>
#endif #endif
#include <spdlog/common.h> #include <spdlog/common.h>

View File

@ -117,5 +117,5 @@ private:
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "thread_pool-inl.h" # include "thread_pool-inl.h"
#endif #endif

View File

@ -1,11 +1,11 @@
#pragma once #pragma once
#ifndef NOMINMAX #ifndef NOMINMAX
#define NOMINMAX // prevent windows redefining min/max # define NOMINMAX // prevent windows redefining min/max
#endif #endif
#ifndef WIN32_LEAN_AND_MEAN #ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN
#endif #endif
#include <windows.h> #include <windows.h>

View File

@ -9,12 +9,12 @@
// //
#if !defined(SPDLOG_FMT_EXTERNAL) #if !defined(SPDLOG_FMT_EXTERNAL)
#ifdef SPDLOG_HEADER_ONLY # ifdef SPDLOG_HEADER_ONLY
#ifndef FMT_HEADER_ONLY # ifndef FMT_HEADER_ONLY
#define FMT_HEADER_ONLY # define FMT_HEADER_ONLY
#endif # endif
#endif # endif
#include <spdlog/fmt/bundled/chrono.h> # include <spdlog/fmt/bundled/chrono.h>
#else #else
#include <fmt/chrono.h> # include <fmt/chrono.h>
#endif #endif

View File

@ -9,12 +9,12 @@
// //
#if !defined(SPDLOG_FMT_EXTERNAL) #if !defined(SPDLOG_FMT_EXTERNAL)
#ifdef SPDLOG_HEADER_ONLY # ifdef SPDLOG_HEADER_ONLY
#ifndef FMT_HEADER_ONLY # ifndef FMT_HEADER_ONLY
#define FMT_HEADER_ONLY # define FMT_HEADER_ONLY
#endif # endif
#endif # endif
#include <spdlog/fmt/bundled/compile.h> # include <spdlog/fmt/bundled/compile.h>
#else #else
#include <fmt/compile.h> # include <fmt/compile.h>
#endif #endif

View File

@ -11,18 +11,17 @@
// //
#if !defined(SPDLOG_FMT_EXTERNAL) #if !defined(SPDLOG_FMT_EXTERNAL)
#if !defined(SPDLOG_COMPILED_LIB) && !defined(FMT_HEADER_ONLY) # if !defined(SPDLOG_COMPILED_LIB) && !defined(FMT_HEADER_ONLY)
#define FMT_HEADER_ONLY # define FMT_HEADER_ONLY
#endif # endif
#ifndef FMT_USE_WINDOWS_H # ifndef FMT_USE_WINDOWS_H
#define FMT_USE_WINDOWS_H 0 # define FMT_USE_WINDOWS_H 0
#endif # endif
// enable the 'n' flag in for backward compatibility with fmt 6.x // enable the 'n' flag in for backward compatibility with fmt 6.x
#define FMT_DEPRECATED_N_SPECIFIER # define FMT_DEPRECATED_N_SPECIFIER
#include <spdlog/fmt/bundled/core.h> # include <spdlog/fmt/bundled/core.h>
#include <spdlog/fmt/bundled/format.h> # include <spdlog/fmt/bundled/format.h>
#else // SPDLOG_FMT_EXTERNAL is defined - use external fmtlib #else // SPDLOG_FMT_EXTERNAL is defined - use external fmtlib
#include <fmt/core.h> # include <fmt/core.h>
#include <fmt/format.h> # include <fmt/format.h>
#endif #endif

View File

@ -9,12 +9,12 @@
// //
#if !defined(SPDLOG_FMT_EXTERNAL) #if !defined(SPDLOG_FMT_EXTERNAL)
#ifdef SPDLOG_HEADER_ONLY # ifdef SPDLOG_HEADER_ONLY
#ifndef FMT_HEADER_ONLY # ifndef FMT_HEADER_ONLY
#define FMT_HEADER_ONLY # define FMT_HEADER_ONLY
#endif # endif
#endif # endif
#include <spdlog/fmt/bundled/ostream.h> # include <spdlog/fmt/bundled/ostream.h>
#else #else
#include <fmt/ostream.h> # include <fmt/ostream.h>
#endif #endif

View File

@ -9,12 +9,12 @@
// //
#if !defined(SPDLOG_FMT_EXTERNAL) #if !defined(SPDLOG_FMT_EXTERNAL)
#ifdef SPDLOG_HEADER_ONLY # ifdef SPDLOG_HEADER_ONLY
#ifndef FMT_HEADER_ONLY # ifndef FMT_HEADER_ONLY
#define FMT_HEADER_ONLY # define FMT_HEADER_ONLY
#endif # endif
#endif # endif
#include <spdlog/fmt/bundled/xchar.h> # include <spdlog/fmt/bundled/xchar.h>
#else #else
#include <fmt/xchar.h> # include <fmt/xchar.h>
#endif #endif

View File

@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/logger.h> # include <spdlog/logger.h>
#endif #endif
#include <spdlog/sinks/sink.h> #include <spdlog/sinks/sink.h>

View File

@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/pattern_formatter.h> # include <spdlog/pattern_formatter.h>
#endif #endif
#include <spdlog/details/fmt_helper.h> #include <spdlog/details/fmt_helper.h>
@ -817,9 +817,9 @@ public:
{} {}
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(push) # pragma warning(push)
#pragma warning(disable : 4127) // consider using 'if constexpr' instead # pragma warning(disable : 4127) // consider using 'if constexpr' instead
#endif // _MSC_VER #endif // _MSC_VER
static const char *basename(const char *filename) static const char *basename(const char *filename)
{ {
// if the size is 2 (1 character + null terminator) we can use the more efficient strrchr // if the size is 2 (1 character + null terminator) we can use the more efficient strrchr
@ -831,15 +831,15 @@ public:
} }
else else
{ {
const std::reverse_iterator<const char*> begin(filename + std::strlen(filename)); const std::reverse_iterator<const char *> begin(filename + std::strlen(filename));
const std::reverse_iterator<const char*> end(filename); const std::reverse_iterator<const char *> end(filename);
const auto it = std::find_first_of(begin, end, std::begin(os::folder_seps), std::end(os::folder_seps) - 1); const auto it = std::find_first_of(begin, end, std::begin(os::folder_seps), std::end(os::folder_seps) - 1);
return it != end ? it.base() : filename; return it != end ? it.base() : filename;
} }
} }
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) # pragma warning(pop)
#endif // _MSC_VER #endif // _MSC_VER
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override

View File

@ -92,7 +92,7 @@ public:
void format(const details::log_msg &msg, memory_buf_t &dest) override; void format(const details::log_msg &msg, memory_buf_t &dest) override;
template<typename T, typename... Args> template<typename T, typename... Args>
pattern_formatter &add_flag(char flag, Args&&...args) pattern_formatter &add_flag(char flag, Args &&...args)
{ {
custom_handlers_[flag] = details::make_unique<T>(std::forward<Args>(args)...); custom_handlers_[flag] = details::make_unique<T>(std::forward<Args>(args)...);
return *this; return *this;
@ -122,5 +122,5 @@ private:
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "pattern_formatter-inl.h" # include "pattern_formatter-inl.h"
#endif #endif

View File

@ -5,21 +5,21 @@
#ifdef __ANDROID__ #ifdef __ANDROID__
#include <spdlog/details/fmt_helper.h> # include <spdlog/details/fmt_helper.h>
#include <spdlog/details/null_mutex.h> # include <spdlog/details/null_mutex.h>
#include <spdlog/details/os.h> # include <spdlog/details/os.h>
#include <spdlog/sinks/base_sink.h> # include <spdlog/sinks/base_sink.h>
#include <spdlog/details/synchronous_factory.h> # include <spdlog/details/synchronous_factory.h>
#include <android/log.h> # include <android/log.h>
#include <chrono> # include <chrono>
#include <mutex> # include <mutex>
#include <string> # include <string>
#include <thread> # include <thread>
#if !defined(SPDLOG_ANDROID_RETRIES) # if !defined(SPDLOG_ANDROID_RETRIES)
#define SPDLOG_ANDROID_RETRIES 2 # define SPDLOG_ANDROID_RETRIES 2
#endif # endif
namespace spdlog { namespace spdlog {
namespace sinks { namespace sinks {

View File

@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/sinks/ansicolor_sink.h> # include <spdlog/sinks/ansicolor_sink.h>
#endif #endif
#include <spdlog/pattern_formatter.h> #include <spdlog/pattern_formatter.h>

View File

@ -114,5 +114,5 @@ using ansicolor_stderr_sink_st = ansicolor_stderr_sink<details::console_nullmute
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "ansicolor_sink-inl.h" # include "ansicolor_sink-inl.h"
#endif #endif

View File

@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/sinks/base_sink.h> # include <spdlog/sinks/base_sink.h>
#endif #endif
#include <spdlog/common.h> #include <spdlog/common.h>

View File

@ -48,5 +48,5 @@ protected:
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "base_sink-inl.h" # include "base_sink-inl.h"
#endif #endif

View File

@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/sinks/basic_file_sink.h> # include <spdlog/sinks/basic_file_sink.h>
#endif #endif
#include <spdlog/common.h> #include <spdlog/common.h>

View File

@ -54,6 +54,5 @@ inline std::shared_ptr<logger> basic_logger_st(const std::string &logger_name, c
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "basic_file_sink-inl.h" # include "basic_file_sink-inl.h"
#endif #endif

View File

@ -31,8 +31,8 @@ struct hourly_filename_calculator
{ {
filename_t basename, ext; filename_t basename, ext;
std::tie(basename, ext) = details::file_helper::split_by_extension(filename); std::tie(basename, ext) = details::file_helper::split_by_extension(filename);
return fmt::format( return fmt::format(SPDLOG_FILENAME_T("{}_{:04d}{:02d}{:02d}_{:02d}{}"), basename, now_tm.tm_year + 1900, now_tm.tm_mon + 1,
SPDLOG_FILENAME_T("{}_{:04d}{:02d}{:02d}_{:02d}{}"), basename, now_tm.tm_year + 1900, now_tm.tm_mon + 1, now_tm.tm_mday, now_tm.tm_hour, ext); now_tm.tm_mday, now_tm.tm_hour, ext);
} }
}; };

View File

@ -8,7 +8,7 @@
// Building and using requires mongocxx library. // Building and using requires mongocxx library.
// For building mongocxx library check the url below // For building mongocxx library check the url below
// http://mongocxx.org/mongocxx-v3/installation/ // http://mongocxx.org/mongocxx-v3/installation/
// //
#include "spdlog/common.h" #include "spdlog/common.h"
#include "spdlog/details/log_msg.h" #include "spdlog/details/log_msg.h"
@ -25,45 +25,52 @@
namespace spdlog { namespace spdlog {
namespace sinks { namespace sinks {
template <typename Mutex> class mongo_sink : public base_sink<Mutex> { template<typename Mutex>
class mongo_sink : public base_sink<Mutex>
{
public: public:
mongo_sink(const std::string &db_name, const std::string &collection_name, mongo_sink(const std::string &db_name, const std::string &collection_name, const std::string &uri = "mongodb://localhost:27017")
const std::string &uri = "mongodb://localhost:27017") { {
try { try
client_ = std::make_unique<mongocxx::client>(mongocxx::uri{uri}); {
db_name_ = db_name; client_ = std::make_unique<mongocxx::client>(mongocxx::uri{uri});
coll_name_ = collection_name; db_name_ = db_name;
} catch (const std::exception) { coll_name_ = collection_name;
throw spdlog_ex("Error opening database"); }
catch (const std::exception)
{
throw spdlog_ex("Error opening database");
}
} }
}
~mongo_sink() { flush_(); } ~mongo_sink()
{
flush_();
}
protected: protected:
void sink_it_(const details::log_msg &msg) override { void sink_it_(const details::log_msg &msg) override
using bsoncxx::builder::stream::document; {
using bsoncxx::builder::stream::finalize; using bsoncxx::builder::stream::document;
using bsoncxx::builder::stream::finalize;
if (client_ != nullptr) { if (client_ != nullptr)
auto doc = document{} {
<< "timestamp" << bsoncxx::types::b_date(msg.time) << "level" auto doc = document{} << "timestamp" << bsoncxx::types::b_date(msg.time) << "level" << level::to_string_view(msg.level).data()
<< level::to_string_view(msg.level).data() << "message" << "message" << std::string(msg.payload.begin(), msg.payload.end()) << "logger_name"
<< std::string(msg.payload.begin(), msg.payload.end()) << std::string(msg.logger_name.begin(), msg.logger_name.end()) << "thread_id"
<< "logger_name" << static_cast<int>(msg.thread_id) << finalize;
<< std::string(msg.logger_name.begin(), msg.logger_name.end()) client_->database(db_name_).collection(coll_name_).insert_one(doc.view());
<< "thread_id" << static_cast<int>(msg.thread_id) << finalize; }
client_->database(db_name_).collection(coll_name_).insert_one(doc.view());
} }
}
void flush_() override {} void flush_() override {}
private: private:
static mongocxx::instance instance_; static mongocxx::instance instance_;
std::string db_name_; std::string db_name_;
std::string coll_name_; std::string coll_name_;
std::unique_ptr<mongocxx::client> client_ = nullptr; std::unique_ptr<mongocxx::client> client_ = nullptr;
}; };
mongocxx::instance mongo_sink<std::mutex>::instance_{}; mongocxx::instance mongo_sink<std::mutex>::instance_{};
@ -73,24 +80,19 @@ using mongo_sink_mt = mongo_sink<std::mutex>;
using mongo_sink_st = mongo_sink<spdlog::details::null_mutex>; using mongo_sink_st = mongo_sink<spdlog::details::null_mutex>;
} // namespace sinks } // namespace sinks
template <typename Factory = spdlog::synchronous_factory> template<typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger> inline std::shared_ptr<logger> mongo_logger_mt(const std::string &logger_name, const std::string &db_name,
mongo_logger_mt(const std::string &logger_name, const std::string &db_name, const std::string &collection_name, const std::string &uri = "mongodb://localhost:27017")
const std::string &collection_name, {
const std::string &uri = "mongodb://localhost:27017") { return Factory::template create<sinks::mongo_sink_mt>(logger_name, db_name, collection_name, uri);
return Factory::template create<sinks::mongo_sink_mt>(logger_name, db_name,
collection_name, uri);
} }
template <typename Factory = spdlog::synchronous_factory> template<typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger> inline std::shared_ptr<logger> mongo_logger_st(const std::string &logger_name, const std::string &db_name,
mongo_logger_st(const std::string &logger_name, const std::string &db_name, const std::string &collection_name, const std::string &uri = "mongodb://localhost:27017")
const std::string &collection_name, {
const std::string &uri = "mongodb://localhost:27017") { return Factory::template create<sinks::mongo_sink_st>(logger_name, db_name, collection_name, uri);
return Factory::template create<sinks::mongo_sink_st>(logger_name, db_name,
collection_name, uri);
} }
} // namespace spdlog } // namespace spdlog

View File

@ -5,12 +5,11 @@
#if defined(_WIN32) #if defined(_WIN32)
#include <spdlog/details/null_mutex.h> # include <spdlog/details/null_mutex.h>
#include <spdlog/sinks/base_sink.h> # include <spdlog/sinks/base_sink.h>
#include <mutex>
#include <string>
# include <mutex>
# include <string>
// Avoid including windows.h (https://stackoverflow.com/a/30741042) // Avoid including windows.h (https://stackoverflow.com/a/30741042)
extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char *lpOutputString); extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char *lpOutputString);

View File

@ -1,187 +1,200 @@
// Copyright(c) 2015-present, Gabi Melman, mguludag and spdlog contributors. // Copyright(c) 2015-present, Gabi Melman, mguludag and spdlog contributors.
// Distributed under the MIT License (http://opensource.org/licenses/MIT) // Distributed under the MIT License (http://opensource.org/licenses/MIT)
#pragma once #pragma once
// //
// Custom sink for QPlainTextEdit or QTextEdit and its children(QTextBrowser... // Custom sink for QPlainTextEdit or QTextEdit and its children(QTextBrowser...
// etc) Building and using requires Qt library. // etc) Building and using requires Qt library.
// //
#include "spdlog/common.h" #include "spdlog/common.h"
#include "spdlog/details/log_msg.h" #include "spdlog/details/log_msg.h"
#include "spdlog/details/synchronous_factory.h" #include "spdlog/details/synchronous_factory.h"
#include "spdlog/sinks/base_sink.h" #include "spdlog/sinks/base_sink.h"
#include <QObject> #include <QObject>
#include <QPlainTextEdit> #include <QPlainTextEdit>
#include <QTextEdit> #include <QTextEdit>
namespace _spdlog_p { namespace _spdlog_p {
namespace _sinks_p { namespace _sinks_p {
// //
// Private class for QTextEdit and its derivatives // Private class for QTextEdit and its derivatives
// //
class qtextedit_sink_p : public QObject { class qtextedit_sink_p : public QObject
Q_OBJECT {
public: Q_OBJECT
qtextedit_sink_p(QTextEdit *textedit = nullptr) { public:
if (textedit != nullptr) { qtextedit_sink_p(QTextEdit *textedit = nullptr)
textedit_ = textedit; {
connect(this, &qtextedit_sink_p::append_text, textedit_, if (textedit != nullptr)
&QTextEdit::append); {
} textedit_ = textedit;
} connect(this, &qtextedit_sink_p::append_text, textedit_, &QTextEdit::append);
}
~qtextedit_sink_p() {} }
void append(const spdlog::string_view_t &str) { ~qtextedit_sink_p() {}
emit append_text(
QString::fromUtf8(str.data(), static_cast<int>(str.size() - 2))); void append(const spdlog::string_view_t &str)
} {
emit append_text(QString::fromUtf8(str.data(), static_cast<int>(str.size() - 2)));
signals: }
void append_text(const QString &);
signals:
private: void append_text(const QString &);
QTextEdit *textedit_ = nullptr;
}; private:
QTextEdit *textedit_ = nullptr;
// };
// Private class for QPlainTextEdit
// //
class qplaintextedit_sink_p : public QObject { // Private class for QPlainTextEdit
Q_OBJECT //
public: class qplaintextedit_sink_p : public QObject
qplaintextedit_sink_p(QPlainTextEdit *textedit = nullptr) { {
if (textedit != nullptr) { Q_OBJECT
textedit_ = textedit; public:
connect(this, &qplaintextedit_sink_p::append_text, textedit_, qplaintextedit_sink_p(QPlainTextEdit *textedit = nullptr)
&QPlainTextEdit::appendPlainText); {
} if (textedit != nullptr)
} {
textedit_ = textedit;
~qplaintextedit_sink_p() {} connect(this, &qplaintextedit_sink_p::append_text, textedit_, &QPlainTextEdit::appendPlainText);
}
void append(const spdlog::string_view_t &str) { }
emit append_text(
QString::fromUtf8(str.data(), static_cast<int>(str.size() - 2))); ~qplaintextedit_sink_p() {}
}
void append(const spdlog::string_view_t &str)
signals: {
void append_text(const QString &); emit append_text(QString::fromUtf8(str.data(), static_cast<int>(str.size() - 2)));
}
private:
QPlainTextEdit *textedit_ = nullptr; signals:
}; void append_text(const QString &);
} // namespace _sinks_p
} // namespace _spdlog_p private:
QPlainTextEdit *textedit_ = nullptr;
// };
// qtextedit_sink class } // namespace _sinks_p
// } // namespace _spdlog_p
namespace spdlog {
namespace sinks { //
template <typename Mutex> class qtextedit_sink : public base_sink<Mutex> { // qtextedit_sink class
public: //
qtextedit_sink(QTextEdit *textedit = nullptr) { namespace spdlog {
if (textedit != nullptr) { namespace sinks {
textedit_p = template<typename Mutex>
std::make_shared<_spdlog_p::_sinks_p::qtextedit_sink_p>(textedit); class qtextedit_sink : public base_sink<Mutex>
} else { {
throw spdlog_ex("Error opening QTextEdit"); public:
} qtextedit_sink(QTextEdit *textedit = nullptr)
} {
if (textedit != nullptr)
~qtextedit_sink() { flush_(); } {
textedit_p = std::make_shared<_spdlog_p::_sinks_p::qtextedit_sink_p>(textedit);
protected: }
void sink_it_(const details::log_msg &msg) override { else
memory_buf_t formatted; {
base_sink<Mutex>::formatter_->format(msg, formatted); throw spdlog_ex("Error opening QTextEdit");
string_view_t str_v = string_view_t(formatted.data(), formatted.size()); }
textedit_p->append(str_v); }
}
~qtextedit_sink()
void flush_() override {} {
flush_();
private: }
std::shared_ptr<_spdlog_p::_sinks_p::qtextedit_sink_p> textedit_p = nullptr;
}; protected:
void sink_it_(const details::log_msg &msg) override
// {
// qplaintextedit_sink class memory_buf_t formatted;
// base_sink<Mutex>::formatter_->format(msg, formatted);
template <typename Mutex> class qplaintextedit_sink : public base_sink<Mutex> { string_view_t str_v = string_view_t(formatted.data(), formatted.size());
public: textedit_p->append(str_v);
qplaintextedit_sink(QPlainTextEdit *textedit = nullptr) { }
if (textedit != nullptr) {
textedit_p = std::make_shared<_spdlog_p::_sinks_p::qplaintextedit_sink_p>( void flush_() override {}
textedit);
} else { private:
throw spdlog_ex("Error opening QPlainTextEdit"); std::shared_ptr<_spdlog_p::_sinks_p::qtextedit_sink_p> textedit_p = nullptr;
} };
}
//
~qplaintextedit_sink() { flush_(); } // qplaintextedit_sink class
//
protected: template<typename Mutex>
void sink_it_(const details::log_msg &msg) override { class qplaintextedit_sink : public base_sink<Mutex>
memory_buf_t formatted; {
base_sink<Mutex>::formatter_->format(msg, formatted); public:
string_view_t str_v = string_view_t(formatted.data(), formatted.size()); qplaintextedit_sink(QPlainTextEdit *textedit = nullptr)
textedit_p->append(str_v); {
} if (textedit != nullptr)
{
void flush_() override {} textedit_p = std::make_shared<_spdlog_p::_sinks_p::qplaintextedit_sink_p>(textedit);
}
private: else
std::shared_ptr<_spdlog_p::_sinks_p::qplaintextedit_sink_p> textedit_p = {
nullptr; throw spdlog_ex("Error opening QPlainTextEdit");
}; }
}
#include "spdlog/details/null_mutex.h"
#include <mutex> ~qplaintextedit_sink()
using qtextedit_sink_mt = qtextedit_sink<std::mutex>; {
using qtextedit_sink_st = qtextedit_sink<spdlog::details::null_mutex>; flush_();
}
using qplaintextedit_sink_mt = qplaintextedit_sink<std::mutex>;
using qplaintextedit_sink_st = qplaintextedit_sink<spdlog::details::null_mutex>; protected:
void sink_it_(const details::log_msg &msg) override
} // namespace sinks {
memory_buf_t formatted;
// base_sink<Mutex>::formatter_->format(msg, formatted);
// Factory functions string_view_t str_v = string_view_t(formatted.data(), formatted.size());
// textedit_p->append(str_v);
template <typename Factory = spdlog::synchronous_factory> }
inline std::shared_ptr<logger>
qtextedit_logger_mt(const std::string &logger_name, void flush_() override {}
QTextEdit *qtextedit = nullptr) {
return Factory::template create<sinks::qtextedit_sink_mt>(logger_name, private:
qtextedit); std::shared_ptr<_spdlog_p::_sinks_p::qplaintextedit_sink_p> textedit_p = nullptr;
} };
template <typename Factory = spdlog::synchronous_factory> #include "spdlog/details/null_mutex.h"
inline std::shared_ptr<logger> #include <mutex>
qtextedit_logger_st(const std::string &logger_name, using qtextedit_sink_mt = qtextedit_sink<std::mutex>;
QTextEdit *qtextedit = nullptr) { using qtextedit_sink_st = qtextedit_sink<spdlog::details::null_mutex>;
return Factory::template create<sinks::qtextedit_sink_st>(logger_name,
qtextedit); using qplaintextedit_sink_mt = qplaintextedit_sink<std::mutex>;
} using qplaintextedit_sink_st = qplaintextedit_sink<spdlog::details::null_mutex>;
template <typename Factory = spdlog::synchronous_factory> } // namespace sinks
inline std::shared_ptr<logger>
qplaintextedit_logger_mt(const std::string &logger_name, //
QPlainTextEdit *qplaintextedit = nullptr) { // Factory functions
return Factory::template create<sinks::qplaintextedit_sink_mt>( //
logger_name, qplaintextedit); template<typename Factory = spdlog::synchronous_factory>
} inline std::shared_ptr<logger> qtextedit_logger_mt(const std::string &logger_name, QTextEdit *qtextedit = nullptr)
{
template <typename Factory = spdlog::synchronous_factory> return Factory::template create<sinks::qtextedit_sink_mt>(logger_name, qtextedit);
inline std::shared_ptr<logger> }
qplaintextedit_logger_st(const std::string &logger_name,
QPlainTextEdit *qplaintextedit = nullptr) { template<typename Factory = spdlog::synchronous_factory>
return Factory::template create<sinks::qplaintextedit_sink_st>( inline std::shared_ptr<logger> qtextedit_logger_st(const std::string &logger_name, QTextEdit *qtextedit = nullptr)
logger_name, qplaintextedit); {
} return Factory::template create<sinks::qtextedit_sink_st>(logger_name, qtextedit);
} // namespace spdlog }
template<typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger> qplaintextedit_logger_mt(const std::string &logger_name, QPlainTextEdit *qplaintextedit = nullptr)
{
return Factory::template create<sinks::qplaintextedit_sink_mt>(logger_name, qplaintextedit);
}
template<typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger> qplaintextedit_logger_st(const std::string &logger_name, QPlainTextEdit *qplaintextedit = nullptr)
{
return Factory::template create<sinks::qplaintextedit_sink_st>(logger_name, qplaintextedit);
}
} // namespace spdlog

View File

@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/sinks/rotating_file_sink.h> # include <spdlog/sinks/rotating_file_sink.h>
#endif #endif
#include <spdlog/common.h> #include <spdlog/common.h>

View File

@ -74,5 +74,5 @@ inline std::shared_ptr<logger> rotating_logger_st(
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "rotating_file_sink-inl.h" # include "rotating_file_sink-inl.h"
#endif #endif

View File

@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/sinks/sink.h> # include <spdlog/sinks/sink.h>
#endif #endif
#include <spdlog/common.h> #include <spdlog/common.h>

View File

@ -31,5 +31,5 @@ protected:
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "sink-inl.h" # include "sink-inl.h"
#endif #endif

View File

@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/sinks/stdout_color_sinks.h> # include <spdlog/sinks/stdout_color_sinks.h>
#endif #endif
#include <spdlog/logger.h> #include <spdlog/logger.h>
@ -36,4 +36,3 @@ SPDLOG_INLINE std::shared_ptr<logger> stderr_color_st(const std::string &logger_
return Factory::template create<sinks::stderr_color_sink_st>(logger_name, mode); return Factory::template create<sinks::stderr_color_sink_st>(logger_name, mode);
} }
} // namespace spdlog } // namespace spdlog

View File

@ -4,9 +4,9 @@
#pragma once #pragma once
#ifdef _WIN32 #ifdef _WIN32
#include <spdlog/sinks/wincolor_sink.h> # include <spdlog/sinks/wincolor_sink.h>
#else #else
#include <spdlog/sinks/ansicolor_sink.h> # include <spdlog/sinks/ansicolor_sink.h>
#endif #endif
#include <spdlog/details/synchronous_factory.h> #include <spdlog/details/synchronous_factory.h>
@ -41,5 +41,5 @@ std::shared_ptr<logger> stderr_color_st(const std::string &logger_name, color_mo
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "stdout_color_sinks-inl.h" # include "stdout_color_sinks-inl.h"
#endif #endif

View File

@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/sinks/stdout_sinks.h> # include <spdlog/sinks/stdout_sinks.h>
#endif #endif
#include <spdlog/details/console_globals.h> #include <spdlog/details/console_globals.h>
@ -14,15 +14,15 @@
#ifdef _WIN32 #ifdef _WIN32
// under windows using fwrite to non-binary stream results in \r\r\n (see issue #1675) // under windows using fwrite to non-binary stream results in \r\r\n (see issue #1675)
// so instead we use ::FileWrite // so instead we use ::FileWrite
#include <spdlog/details/windows_include.h> # include <spdlog/details/windows_include.h>
#ifndef _USING_V110_SDK71_ // fileapi.h doesnt exist in winxp # ifndef _USING_V110_SDK71_ // fileapi.h doesnt exist in winxp
#include <fileapi.h> // WriteFile (..) # include <fileapi.h> // WriteFile (..)
#endif # endif
#include <io.h> // _get_osfhandle(..) # include <io.h> // _get_osfhandle(..)
#include <stdio.h> // _fileno(..) # include <stdio.h> // _fileno(..)
#endif // WIN32 #endif // WIN32
namespace spdlog { namespace spdlog {
@ -36,9 +36,9 @@ SPDLOG_INLINE stdout_sink_base<ConsoleMutex>::stdout_sink_base(FILE *file)
{ {
#ifdef _WIN32 #ifdef _WIN32
// get windows handle from the FILE* object // get windows handle from the FILE* object
handle_ = (HANDLE)::_get_osfhandle(::_fileno(file_)); handle_ = (HANDLE)::_get_osfhandle(::_fileno(file_));
// don't throw to support cases where no console is attached, // don't throw to support cases where no console is attached,
// and let the log method to do nothing if (handle_ == INVALID_HANDLE_VALUE). // and let the log method to do nothing if (handle_ == INVALID_HANDLE_VALUE).
// throw only if non stdout/stderr target is requested (probably regular file and not console). // throw only if non stdout/stderr target is requested (probably regular file and not console).
@ -54,7 +54,7 @@ SPDLOG_INLINE void stdout_sink_base<ConsoleMutex>::log(const details::log_msg &m
{ {
#ifdef _WIN32 #ifdef _WIN32
if (handle_ == INVALID_HANDLE_VALUE) if (handle_ == INVALID_HANDLE_VALUE)
{ {
return; return;
} }
std::lock_guard<mutex_t> lock(mutex_); std::lock_guard<mutex_t> lock(mutex_);
@ -74,7 +74,7 @@ SPDLOG_INLINE void stdout_sink_base<ConsoleMutex>::log(const details::log_msg &m
formatter_->format(msg, formatted); formatter_->format(msg, formatted);
::fwrite(formatted.data(), sizeof(char), formatted.size(), file_); ::fwrite(formatted.data(), sizeof(char), formatted.size(), file_);
::fflush(file_); // flush every line to terminal ::fflush(file_); // flush every line to terminal
#endif // WIN32 #endif // WIN32
} }
template<typename ConsoleMutex> template<typename ConsoleMutex>

View File

@ -9,7 +9,7 @@
#include <cstdio> #include <cstdio>
#ifdef _WIN32 #ifdef _WIN32
#include <spdlog/details/windows_include.h> # include <spdlog/details/windows_include.h>
#endif #endif
namespace spdlog { namespace spdlog {
@ -41,7 +41,7 @@ protected:
FILE *file_; FILE *file_;
std::unique_ptr<spdlog::formatter> formatter_; std::unique_ptr<spdlog::formatter> formatter_;
#ifdef _WIN32 #ifdef _WIN32
HANDLE handle_; HANDLE handle_;
#endif // WIN32 #endif // WIN32
}; };
@ -83,5 +83,5 @@ std::shared_ptr<logger> stderr_logger_st(const std::string &logger_name);
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "stdout_sinks-inl.h" # include "stdout_sinks-inl.h"
#endif #endif

View File

@ -9,7 +9,7 @@
#include <array> #include <array>
#ifndef SD_JOURNAL_SUPPRESS_LOCATION #ifndef SD_JOURNAL_SUPPRESS_LOCATION
#define SD_JOURNAL_SUPPRESS_LOCATION # define SD_JOURNAL_SUPPRESS_LOCATION
#endif #endif
#include <systemd/sd-journal.h> #include <systemd/sd-journal.h>

View File

@ -7,9 +7,9 @@
#include <spdlog/sinks/base_sink.h> #include <spdlog/sinks/base_sink.h>
#include <spdlog/details/null_mutex.h> #include <spdlog/details/null_mutex.h>
#ifdef _WIN32 #ifdef _WIN32
#include <spdlog/details/tcp_client-windows.h> # include <spdlog/details/tcp_client-windows.h>
#else #else
#include <spdlog/details/tcp_client.h> # include <spdlog/details/tcp_client.h>
#endif #endif
#include <mutex> #include <mutex>

View File

@ -229,11 +229,11 @@ protected:
LPCWSTR lp_wstr = buf.data(); LPCWSTR lp_wstr = buf.data();
succeeded = ::ReportEventW(event_log_handle(), eventlog::get_event_type(msg), eventlog::get_event_category(msg), event_id_, succeeded = ::ReportEventW(event_log_handle(), eventlog::get_event_type(msg), eventlog::get_event_category(msg), event_id_,
current_user_sid_.as_sid(), 1, 0, &lp_wstr, nullptr); current_user_sid_.as_sid(), 1, 0, &lp_wstr, nullptr);
#else #else
LPCSTR lp_str = formatted.data(); LPCSTR lp_str = formatted.data();
succeeded = ::ReportEventA(event_log_handle(), eventlog::get_event_type(msg), eventlog::get_event_category(msg), event_id_, succeeded = ::ReportEventA(event_log_handle(), eventlog::get_event_type(msg), eventlog::get_event_category(msg), event_id_,
current_user_sid_.as_sid(), 1, 0, &lp_str, nullptr); current_user_sid_.as_sid(), 1, 0, &lp_str, nullptr);
#endif #endif
if (!succeeded) if (!succeeded)

View File

@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/sinks/wincolor_sink.h> # include <spdlog/sinks/wincolor_sink.h>
#endif #endif
#include <spdlog/details/windows_include.h> #include <spdlog/details/windows_include.h>
@ -129,10 +129,10 @@ std::uint16_t SPDLOG_INLINE wincolor_sink<ConsoleMutex>::set_foreground_color_(s
if (!::GetConsoleScreenBufferInfo(static_cast<HANDLE>(out_handle_), &orig_buffer_info)) if (!::GetConsoleScreenBufferInfo(static_cast<HANDLE>(out_handle_), &orig_buffer_info))
{ {
// just return white if failed getting console info // just return white if failed getting console info
return FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; return FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
} }
// change only the foreground bits (lowest 4 bits) // change only the foreground bits (lowest 4 bits)
auto new_attribs = static_cast<WORD>(attribs) | (orig_buffer_info.wAttributes & 0xfff0); auto new_attribs = static_cast<WORD>(attribs) | (orig_buffer_info.wAttributes & 0xfff0);
auto ignored = ::SetConsoleTextAttribute(static_cast<HANDLE>(out_handle_), static_cast<WORD>(new_attribs)); auto ignored = ::SetConsoleTextAttribute(static_cast<HANDLE>(out_handle_), static_cast<WORD>(new_attribs));
(void)(ignored); (void)(ignored);

View File

@ -23,7 +23,7 @@ namespace sinks {
template<typename ConsoleMutex> template<typename ConsoleMutex>
class wincolor_sink : public sink class wincolor_sink : public sink
{ {
public: public:
wincolor_sink(void *out_handle, color_mode mode); wincolor_sink(void *out_handle, color_mode mode);
~wincolor_sink() override; ~wincolor_sink() override;
@ -41,7 +41,7 @@ public:
protected: protected:
using mutex_t = typename ConsoleMutex::mutex_t; using mutex_t = typename ConsoleMutex::mutex_t;
void *out_handle_; void *out_handle_;
mutex_t &mutex_; mutex_t &mutex_;
bool should_do_colors_; bool should_do_colors_;
std::unique_ptr<spdlog::formatter> formatter_; std::unique_ptr<spdlog::formatter> formatter_;
std::array<std::uint16_t, level::n_levels> colors_; std::array<std::uint16_t, level::n_levels> colors_;
@ -81,5 +81,5 @@ using wincolor_stderr_sink_st = wincolor_stderr_sink<details::console_nullmutex>
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "wincolor_sink-inl.h" # include "wincolor_sink-inl.h"
#endif #endif

View File

@ -4,7 +4,7 @@
#pragma once #pragma once
#ifndef SPDLOG_HEADER_ONLY #ifndef SPDLOG_HEADER_ONLY
#include <spdlog/spdlog.h> # include <spdlog/spdlog.h>
#endif #endif
#include <spdlog/common.h> #include <spdlog/common.h>

View File

@ -128,49 +128,49 @@ SPDLOG_API spdlog::logger *default_logger_raw();
SPDLOG_API void set_default_logger(std::shared_ptr<spdlog::logger> default_logger); SPDLOG_API void set_default_logger(std::shared_ptr<spdlog::logger> default_logger);
template<typename FormatString, typename... Args> template<typename FormatString, typename... Args>
inline void log(source_loc source, level::level_enum lvl, const FormatString &fmt, Args&&...args) inline void log(source_loc source, level::level_enum lvl, const FormatString &fmt, Args &&...args)
{ {
default_logger_raw()->log(source, lvl, fmt, std::forward<Args>(args)...); default_logger_raw()->log(source, lvl, fmt, std::forward<Args>(args)...);
} }
template<typename FormatString, typename... Args> template<typename FormatString, typename... Args>
inline void log(level::level_enum lvl, const FormatString &fmt, Args&&...args) inline void log(level::level_enum lvl, const FormatString &fmt, Args &&...args)
{ {
default_logger_raw()->log(source_loc{}, lvl, fmt, std::forward<Args>(args)...); default_logger_raw()->log(source_loc{}, lvl, fmt, std::forward<Args>(args)...);
} }
template<typename FormatString, typename... Args> template<typename FormatString, typename... Args>
inline void trace(const FormatString &fmt, Args&&...args) inline void trace(const FormatString &fmt, Args &&...args)
{ {
default_logger_raw()->trace(fmt, std::forward<Args>(args)...); default_logger_raw()->trace(fmt, std::forward<Args>(args)...);
} }
template<typename FormatString, typename... Args> template<typename FormatString, typename... Args>
inline void debug(const FormatString &fmt, Args&&...args) inline void debug(const FormatString &fmt, Args &&...args)
{ {
default_logger_raw()->debug(fmt, std::forward<Args>(args)...); default_logger_raw()->debug(fmt, std::forward<Args>(args)...);
} }
template<typename FormatString, typename... Args> template<typename FormatString, typename... Args>
inline void info(const FormatString &fmt, Args&&...args) inline void info(const FormatString &fmt, Args &&...args)
{ {
default_logger_raw()->info(fmt, std::forward<Args>(args)...); default_logger_raw()->info(fmt, std::forward<Args>(args)...);
} }
template<typename FormatString, typename... Args> template<typename FormatString, typename... Args>
inline void warn(const FormatString &fmt, Args&&...args) inline void warn(const FormatString &fmt, Args &&...args)
{ {
default_logger_raw()->warn(fmt, std::forward<Args>(args)...); default_logger_raw()->warn(fmt, std::forward<Args>(args)...);
} }
template<typename FormatString, typename... Args> template<typename FormatString, typename... Args>
inline void error(const FormatString &fmt, Args&&...args) inline void error(const FormatString &fmt, Args &&...args)
{ {
default_logger_raw()->error(fmt, std::forward<Args>(args)...); default_logger_raw()->error(fmt, std::forward<Args>(args)...);
} }
template<typename FormatString, typename... Args> template<typename FormatString, typename... Args>
inline void critical(const FormatString &fmt, Args&&...args) inline void critical(const FormatString &fmt, Args &&...args)
{ {
default_logger_raw()->critical(fmt, std::forward<Args>(args)...); default_logger_raw()->critical(fmt, std::forward<Args>(args)...);
} }
@ -241,55 +241,55 @@ inline void critical(const T &msg)
#define SPDLOG_LOGGER_CALL(logger, level, ...) (logger)->log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__) #define SPDLOG_LOGGER_CALL(logger, level, ...) (logger)->log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__)
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
#define SPDLOG_LOGGER_TRACE(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::trace, __VA_ARGS__) # define SPDLOG_LOGGER_TRACE(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::trace, __VA_ARGS__)
#define SPDLOG_TRACE(...) SPDLOG_LOGGER_TRACE(spdlog::default_logger_raw(), __VA_ARGS__) # define SPDLOG_TRACE(...) SPDLOG_LOGGER_TRACE(spdlog::default_logger_raw(), __VA_ARGS__)
#else #else
#define SPDLOG_LOGGER_TRACE(logger, ...) (void)0 # define SPDLOG_LOGGER_TRACE(logger, ...) (void)0
#define SPDLOG_TRACE(...) (void)0 # define SPDLOG_TRACE(...) (void)0
#endif #endif
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_DEBUG #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_DEBUG
#define SPDLOG_LOGGER_DEBUG(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::debug, __VA_ARGS__) # define SPDLOG_LOGGER_DEBUG(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::debug, __VA_ARGS__)
#define SPDLOG_DEBUG(...) SPDLOG_LOGGER_DEBUG(spdlog::default_logger_raw(), __VA_ARGS__) # define SPDLOG_DEBUG(...) SPDLOG_LOGGER_DEBUG(spdlog::default_logger_raw(), __VA_ARGS__)
#else #else
#define SPDLOG_LOGGER_DEBUG(logger, ...) (void)0 # define SPDLOG_LOGGER_DEBUG(logger, ...) (void)0
#define SPDLOG_DEBUG(...) (void)0 # define SPDLOG_DEBUG(...) (void)0
#endif #endif
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_INFO #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_INFO
#define SPDLOG_LOGGER_INFO(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::info, __VA_ARGS__) # define SPDLOG_LOGGER_INFO(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::info, __VA_ARGS__)
#define SPDLOG_INFO(...) SPDLOG_LOGGER_INFO(spdlog::default_logger_raw(), __VA_ARGS__) # define SPDLOG_INFO(...) SPDLOG_LOGGER_INFO(spdlog::default_logger_raw(), __VA_ARGS__)
#else #else
#define SPDLOG_LOGGER_INFO(logger, ...) (void)0 # define SPDLOG_LOGGER_INFO(logger, ...) (void)0
#define SPDLOG_INFO(...) (void)0 # define SPDLOG_INFO(...) (void)0
#endif #endif
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_WARN #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_WARN
#define SPDLOG_LOGGER_WARN(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::warn, __VA_ARGS__) # define SPDLOG_LOGGER_WARN(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::warn, __VA_ARGS__)
#define SPDLOG_WARN(...) SPDLOG_LOGGER_WARN(spdlog::default_logger_raw(), __VA_ARGS__) # define SPDLOG_WARN(...) SPDLOG_LOGGER_WARN(spdlog::default_logger_raw(), __VA_ARGS__)
#else #else
#define SPDLOG_LOGGER_WARN(logger, ...) (void)0 # define SPDLOG_LOGGER_WARN(logger, ...) (void)0
#define SPDLOG_WARN(...) (void)0 # define SPDLOG_WARN(...) (void)0
#endif #endif
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_ERROR #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_ERROR
#define SPDLOG_LOGGER_ERROR(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::err, __VA_ARGS__) # define SPDLOG_LOGGER_ERROR(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::err, __VA_ARGS__)
#define SPDLOG_ERROR(...) SPDLOG_LOGGER_ERROR(spdlog::default_logger_raw(), __VA_ARGS__) # define SPDLOG_ERROR(...) SPDLOG_LOGGER_ERROR(spdlog::default_logger_raw(), __VA_ARGS__)
#else #else
#define SPDLOG_LOGGER_ERROR(logger, ...) (void)0 # define SPDLOG_LOGGER_ERROR(logger, ...) (void)0
#define SPDLOG_ERROR(...) (void)0 # define SPDLOG_ERROR(...) (void)0
#endif #endif
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_CRITICAL #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_CRITICAL
#define SPDLOG_LOGGER_CRITICAL(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::critical, __VA_ARGS__) # define SPDLOG_LOGGER_CRITICAL(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::critical, __VA_ARGS__)
#define SPDLOG_CRITICAL(...) SPDLOG_LOGGER_CRITICAL(spdlog::default_logger_raw(), __VA_ARGS__) # define SPDLOG_CRITICAL(...) SPDLOG_LOGGER_CRITICAL(spdlog::default_logger_raw(), __VA_ARGS__)
#else #else
#define SPDLOG_LOGGER_CRITICAL(logger, ...) (void)0 # define SPDLOG_LOGGER_CRITICAL(logger, ...) (void)0
#define SPDLOG_CRITICAL(...) (void)0 # define SPDLOG_CRITICAL(...) (void)0
#endif #endif
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
#include "spdlog-inl.h" # include "spdlog-inl.h"
#endif #endif
#endif // SPDLOG_H #endif // SPDLOG_H

View File

@ -2,7 +2,7 @@
// Distributed under the MIT License (http://opensource.org/licenses/MIT) // Distributed under the MIT License (http://opensource.org/licenses/MIT)
#ifndef SPDLOG_COMPILED_LIB #ifndef SPDLOG_COMPILED_LIB
#error Please define SPDLOG_COMPILED_LIB to compile this file. # error Please define SPDLOG_COMPILED_LIB to compile this file.
#endif #endif
#include <spdlog/async.h> #include <spdlog/async.h>
@ -11,4 +11,3 @@
#include <spdlog/details/thread_pool-inl.h> #include <spdlog/details/thread_pool-inl.h>
template class SPDLOG_API spdlog::details::mpmc_blocking_queue<spdlog::details::async_msg>; template class SPDLOG_API spdlog::details::mpmc_blocking_queue<spdlog::details::async_msg>;

View File

@ -2,8 +2,7 @@
// Distributed under the MIT License (http://opensource.org/licenses/MIT) // Distributed under the MIT License (http://opensource.org/licenses/MIT)
#ifndef SPDLOG_COMPILED_LIB #ifndef SPDLOG_COMPILED_LIB
#error Please define SPDLOG_COMPILED_LIB to compile this file. # error Please define SPDLOG_COMPILED_LIB to compile this file.
#endif #endif
#include <spdlog/cfg/helpers-inl.h> #include <spdlog/cfg/helpers-inl.h>

View File

@ -2,7 +2,7 @@
// Distributed under the MIT License (http://opensource.org/licenses/MIT) // Distributed under the MIT License (http://opensource.org/licenses/MIT)
#ifndef SPDLOG_COMPILED_LIB #ifndef SPDLOG_COMPILED_LIB
#error Please define SPDLOG_COMPILED_LIB to compile this file. # error Please define SPDLOG_COMPILED_LIB to compile this file.
#endif #endif
#include <mutex> #include <mutex>
@ -13,7 +13,7 @@
// color sinks // color sinks
// //
#ifdef _WIN32 #ifdef _WIN32
#include <spdlog/sinks/wincolor_sink-inl.h> # include <spdlog/sinks/wincolor_sink-inl.h>
template class SPDLOG_API spdlog::sinks::wincolor_sink<spdlog::details::console_mutex>; template class SPDLOG_API spdlog::sinks::wincolor_sink<spdlog::details::console_mutex>;
template class SPDLOG_API spdlog::sinks::wincolor_sink<spdlog::details::console_nullmutex>; template class SPDLOG_API spdlog::sinks::wincolor_sink<spdlog::details::console_nullmutex>;
template class SPDLOG_API spdlog::sinks::wincolor_stdout_sink<spdlog::details::console_mutex>; template class SPDLOG_API spdlog::sinks::wincolor_stdout_sink<spdlog::details::console_mutex>;
@ -21,7 +21,7 @@ template class SPDLOG_API spdlog::sinks::wincolor_stdout_sink<spdlog::details::c
template class SPDLOG_API spdlog::sinks::wincolor_stderr_sink<spdlog::details::console_mutex>; template class SPDLOG_API spdlog::sinks::wincolor_stderr_sink<spdlog::details::console_mutex>;
template class SPDLOG_API spdlog::sinks::wincolor_stderr_sink<spdlog::details::console_nullmutex>; template class SPDLOG_API spdlog::sinks::wincolor_stderr_sink<spdlog::details::console_nullmutex>;
#else #else
#include "spdlog/sinks/ansicolor_sink-inl.h" # include "spdlog/sinks/ansicolor_sink-inl.h"
template class SPDLOG_API spdlog::sinks::ansicolor_sink<spdlog::details::console_mutex>; template class SPDLOG_API spdlog::sinks::ansicolor_sink<spdlog::details::console_mutex>;
template class SPDLOG_API spdlog::sinks::ansicolor_sink<spdlog::details::console_nullmutex>; template class SPDLOG_API spdlog::sinks::ansicolor_sink<spdlog::details::console_nullmutex>;
template class SPDLOG_API spdlog::sinks::ansicolor_stdout_sink<spdlog::details::console_mutex>; template class SPDLOG_API spdlog::sinks::ansicolor_stdout_sink<spdlog::details::console_mutex>;
@ -49,4 +49,3 @@ template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stderr_color_mt<spdl
const std::string &logger_name, color_mode mode); const std::string &logger_name, color_mode mode);
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stderr_color_st<spdlog::async_factory>( template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stderr_color_st<spdlog::async_factory>(
const std::string &logger_name, color_mode mode); const std::string &logger_name, color_mode mode);

View File

@ -2,7 +2,7 @@
// Distributed under the MIT License (http://opensource.org/licenses/MIT) // Distributed under the MIT License (http://opensource.org/licenses/MIT)
#ifndef SPDLOG_COMPILED_LIB #ifndef SPDLOG_COMPILED_LIB
#error Please define SPDLOG_COMPILED_LIB to compile this file. # error Please define SPDLOG_COMPILED_LIB to compile this file.
#endif #endif
#include <spdlog/details/null_mutex.h> #include <spdlog/details/null_mutex.h>
@ -18,4 +18,3 @@ template class SPDLOG_API spdlog::sinks::basic_file_sink<spdlog::details::null_m
#include <spdlog/sinks/rotating_file_sink-inl.h> #include <spdlog/sinks/rotating_file_sink-inl.h>
template class SPDLOG_API spdlog::sinks::rotating_file_sink<std::mutex>; template class SPDLOG_API spdlog::sinks::rotating_file_sink<std::mutex>;
template class SPDLOG_API spdlog::sinks::rotating_file_sink<spdlog::details::null_mutex>; template class SPDLOG_API spdlog::sinks::rotating_file_sink<spdlog::details::null_mutex>;

View File

@ -2,7 +2,7 @@
// Distributed under the MIT License (http://opensource.org/licenses/MIT) // Distributed under the MIT License (http://opensource.org/licenses/MIT)
#ifndef SPDLOG_COMPILED_LIB #ifndef SPDLOG_COMPILED_LIB
#error Please define SPDLOG_COMPILED_LIB to compile this file. # error Please define SPDLOG_COMPILED_LIB to compile this file.
#endif #endif
#include <spdlog/spdlog-inl.h> #include <spdlog/spdlog-inl.h>
@ -24,4 +24,3 @@
template SPDLOG_API spdlog::logger::logger(std::string name, sinks_init_list::iterator begin, sinks_init_list::iterator end); template SPDLOG_API spdlog::logger::logger(std::string name, sinks_init_list::iterator begin, sinks_init_list::iterator end);
template class SPDLOG_API spdlog::sinks::base_sink<std::mutex>; template class SPDLOG_API spdlog::sinks::base_sink<std::mutex>;
template class SPDLOG_API spdlog::sinks::base_sink<spdlog::details::null_mutex>; template class SPDLOG_API spdlog::sinks::base_sink<spdlog::details::null_mutex>;

View File

@ -2,7 +2,7 @@
// Distributed under the MIT License (http://opensource.org/licenses/MIT) // Distributed under the MIT License (http://opensource.org/licenses/MIT)
#ifndef SPDLOG_COMPILED_LIB #ifndef SPDLOG_COMPILED_LIB
#error Please define SPDLOG_COMPILED_LIB to compile this file. # error Please define SPDLOG_COMPILED_LIB to compile this file.
#endif #endif
#include <mutex> #include <mutex>
@ -27,4 +27,3 @@ template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stdout_logger_mt<spd
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stdout_logger_st<spdlog::async_factory>(const std::string &logger_name); template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stdout_logger_st<spdlog::async_factory>(const std::string &logger_name);
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stderr_logger_mt<spdlog::async_factory>(const std::string &logger_name); template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stderr_logger_mt<spdlog::async_factory>(const std::string &logger_name);
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stderr_logger_st<spdlog::async_factory>(const std::string &logger_name); template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stderr_logger_st<spdlog::async_factory>(const std::string &logger_name);

View File

@ -27,7 +27,8 @@ TEST_CASE("create_dir", "[create_dir]")
// test backslash folder separator // test backslash folder separator
REQUIRE(try_create_dir(SPDLOG_FILENAME_T("test_logs\\dir1\\dir222"), SPDLOG_FILENAME_T("test_logs\\dir1\\dir222"))); REQUIRE(try_create_dir(SPDLOG_FILENAME_T("test_logs\\dir1\\dir222"), SPDLOG_FILENAME_T("test_logs\\dir1\\dir222")));
REQUIRE(try_create_dir(SPDLOG_FILENAME_T("test_logs\\dir1\\dir223\\"), SPDLOG_FILENAME_T("test_logs\\dir1\\dir223\\"))); REQUIRE(try_create_dir(SPDLOG_FILENAME_T("test_logs\\dir1\\dir223\\"), SPDLOG_FILENAME_T("test_logs\\dir1\\dir223\\")));
REQUIRE(try_create_dir(SPDLOG_FILENAME_T(".\\test_logs\\dir1\\dir2\\dir99\\..\\dir23"), SPDLOG_FILENAME_T("test_logs\\dir1\\dir2\\dir23"))); REQUIRE(
try_create_dir(SPDLOG_FILENAME_T(".\\test_logs\\dir1\\dir2\\dir99\\..\\dir23"), SPDLOG_FILENAME_T("test_logs\\dir1\\dir2\\dir23")));
REQUIRE(try_create_dir(SPDLOG_FILENAME_T("test_logs\\..\\test_logs\\dir1\\dir5"), SPDLOG_FILENAME_T("test_logs\\dir1\\dir5"))); REQUIRE(try_create_dir(SPDLOG_FILENAME_T("test_logs\\..\\test_logs\\dir1\\dir5"), SPDLOG_FILENAME_T("test_logs\\dir1\\dir5")));
#endif #endif
} }

View File

@ -15,7 +15,8 @@ TEST_CASE("daily_logger with dateonly calculator", "[daily_logger]")
spdlog::filename_t basename = SPDLOG_FILENAME_T("test_logs/daily_dateonly"); spdlog::filename_t basename = SPDLOG_FILENAME_T("test_logs/daily_dateonly");
std::tm tm = spdlog::details::os::localtime(); std::tm tm = spdlog::details::os::localtime();
filename_memory_buf_t w; filename_memory_buf_t w;
fmt::format_to(std::back_inserter(w), SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}"), basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday); fmt::format_to(
std::back_inserter(w), SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}"), basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
auto logger = spdlog::create<sink_type>("logger", basename, 0, 0); auto logger = spdlog::create<sink_type>("logger", basename, 0, 0);
for (int i = 0; i < 10; ++i) for (int i = 0; i < 10; ++i)
@ -40,8 +41,8 @@ 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)
{ {
filename_memory_buf_t w; filename_memory_buf_t w;
fmt::format_to(std::back_inserter(w), SPDLOG_FILENAME_T("{}{:04d}{:02d}{:02d}"), basename, now_tm.tm_year + 1900, fmt::format_to(std::back_inserter(w), SPDLOG_FILENAME_T("{}{:04d}{:02d}{:02d}"), basename, now_tm.tm_year + 1900, now_tm.tm_mon + 1,
now_tm.tm_mon + 1, now_tm.tm_mday); now_tm.tm_mday);
return fmt::to_string(w); return fmt::to_string(w);
} }
}; };
@ -56,7 +57,8 @@ TEST_CASE("daily_logger with custom calculator", "[daily_logger]")
spdlog::filename_t basename = SPDLOG_FILENAME_T("test_logs/daily_dateonly"); spdlog::filename_t basename = SPDLOG_FILENAME_T("test_logs/daily_dateonly");
std::tm tm = spdlog::details::os::localtime(); std::tm tm = spdlog::details::os::localtime();
filename_memory_buf_t w; filename_memory_buf_t w;
fmt::format_to(std::back_inserter(w), SPDLOG_FILENAME_T("{}{:04d}{:02d}{:02d}"), basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday); fmt::format_to(
std::back_inserter(w), SPDLOG_FILENAME_T("{}{:04d}{:02d}{:02d}"), basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
auto logger = spdlog::create<sink_type>("logger", basename, 0, 0); auto logger = spdlog::create<sink_type>("logger", basename, 0, 0);
for (int i = 0; i < 10; ++i) for (int i = 0; i < 10; ++i)
@ -101,14 +103,16 @@ TEST_CASE("rotating_file_sink::calc_filename3", "[rotating_file_sink]]")
// regex supported only from gcc 4.9 and above // regex supported only from gcc 4.9 and above
#if defined(_MSC_VER) || !(__GNUC__ <= 4 && __GNUC_MINOR__ < 9) #if defined(_MSC_VER) || !(__GNUC__ <= 4 && __GNUC_MINOR__ < 9)
#include <regex> # include <regex>
TEST_CASE("daily_file_sink::daily_filename_calculator", "[daily_file_sink]]") TEST_CASE("daily_file_sink::daily_filename_calculator", "[daily_file_sink]]")
{ {
// daily_YYYY-MM-DD_hh-mm.txt // daily_YYYY-MM-DD_hh-mm.txt
auto filename = spdlog::sinks::daily_filename_calculator::calc_filename(SPDLOG_FILENAME_T("daily.txt"), spdlog::details::os::localtime()); auto filename =
spdlog::sinks::daily_filename_calculator::calc_filename(SPDLOG_FILENAME_T("daily.txt"), spdlog::details::os::localtime());
// date regex based on https://www.regular-expressions.info/dates.html // date regex based on https://www.regular-expressions.info/dates.html
std::basic_regex<spdlog::filename_t::value_type> re(SPDLOG_FILENAME_T(R"(^daily_(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])\.txt$)")); std::basic_regex<spdlog::filename_t::value_type> re(
SPDLOG_FILENAME_T(R"(^daily_(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])\.txt$)"));
std::match_results<spdlog::filename_t::const_iterator> match; std::match_results<spdlog::filename_t::const_iterator> match;
REQUIRE(std::regex_match(filename, match, re)); REQUIRE(std::regex_match(filename, match, re));
} }

View File

@ -87,5 +87,4 @@ TEST_CASE("dup_filter_test5", "[dup_filter_sink]")
REQUIRE(test_sink->msg_counter() == 3); // skip 2 messages but log the "skipped.." message before message2 REQUIRE(test_sink->msg_counter() == 3); // skip 2 messages but log the "skipped.." message before message2
REQUIRE(test_sink->lines()[1] == "Skipped 2 duplicate messages.."); REQUIRE(test_sink->lines()[1] == "Skipped 2 duplicate messages..");
} }

View File

@ -1,9 +1,9 @@
#if _WIN32 #if _WIN32
#include "includes.h" # include "includes.h"
#include "test_sink.h" # include "test_sink.h"
#include "spdlog/sinks/win_eventlog_sink.h" # include "spdlog/sinks/win_eventlog_sink.h"
static const LPCSTR TEST_SOURCE = "spdlog_test"; static const LPCSTR TEST_SOURCE = "spdlog_test";
@ -29,8 +29,8 @@ static void test_single_print(std::function<void(std::string const &)> do_log, s
REQUIRE(event_log.handle_); REQUIRE(event_log.handle_);
DWORD read_bytes{}, size_needed{}; DWORD read_bytes{}, size_needed{};
auto ok = auto ok = ::ReadEventLogA(
::ReadEventLogA(event_log.handle_, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_BACKWARDS_READ, 0, &read_bytes, 0, &read_bytes, &size_needed); event_log.handle_, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_BACKWARDS_READ, 0, &read_bytes, 0, &read_bytes, &size_needed);
REQUIRE(!ok); REQUIRE(!ok);
REQUIRE(::GetLastError() == ERROR_INSUFFICIENT_BUFFER); REQUIRE(::GetLastError() == ERROR_INSUFFICIENT_BUFFER);

View File

@ -64,7 +64,8 @@ TEST_CASE("file_helper_reopen2", "[file_helper::reopen(false)]]")
REQUIRE(helper.size() == expected_size); REQUIRE(helper.size() == expected_size);
} }
static void test_split_ext(const spdlog::filename_t::value_type *fname, const spdlog::filename_t::value_type *expect_base, const spdlog::filename_t::value_type *expect_ext) static void test_split_ext(const spdlog::filename_t::value_type *fname, const spdlog::filename_t::value_type *expect_base,
const spdlog::filename_t::value_type *expect_ext)
{ {
spdlog::filename_t filename(fname); spdlog::filename_t filename(fname);
spdlog::filename_t expected_base(expect_base); spdlog::filename_t expected_base(expect_base);

View File

@ -5,7 +5,7 @@
#include "includes.h" #include "includes.h"
#if SPDLOG_ACTIVE_LEVEL != SPDLOG_LEVEL_DEBUG #if SPDLOG_ACTIVE_LEVEL != SPDLOG_LEVEL_DEBUG
#error "Invalid SPDLOG_ACTIVE_LEVEL in test. Should be SPDLOG_LEVEL_DEBUG" # error "Invalid SPDLOG_ACTIVE_LEVEL in test. Should be SPDLOG_LEVEL_DEBUG"
#endif #endif
#define TEST_FILENAME "test_logs/simple_log" #define TEST_FILENAME "test_logs/simple_log"

View File

@ -1,10 +1,10 @@
#include "includes.h" #include "includes.h"
#ifdef _WIN32 #ifdef _WIN32
#include <Windows.h> # include <Windows.h>
#else #else
#include <sys/types.h> # include <sys/types.h>
#include <dirent.h> # include <dirent.h>
#endif #endif
void prepare_logdir() void prepare_logdir()