error handler wip
This commit is contained in:
parent
833bb360a3
commit
0fd3e80794
292
CMakeLists.txt
292
CMakeLists.txt
@ -19,38 +19,38 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
|||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
# Set default build to release
|
# Set default build to release
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
||||||
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose Release or Debug" FORCE)
|
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose Release or Debug" FORCE)
|
||||||
endif()
|
endif ()
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
# Compiler config
|
# Compiler config
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
# c++ standard >=17 is required
|
# c++ standard >=17 is required
|
||||||
if(NOT DEFINED CMAKE_CXX_STANDARD)
|
if (NOT DEFINED CMAKE_CXX_STANDARD)
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
elseif(CMAKE_CXX_STANDARD LESS 17)
|
elseif (CMAKE_CXX_STANDARD LESS 17)
|
||||||
message(FATAL_ERROR "Minimum supported CMAKE_CXX_STANDARD is 17, but it is set to ${CMAKE_CXX_STANDARD}")
|
message(FATAL_ERROR "Minimum supported CMAKE_CXX_STANDARD is 17, but it is set to ${CMAKE_CXX_STANDARD}")
|
||||||
endif()
|
endif ()
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
|
||||||
if(CMAKE_SYSTEM_NAME MATCHES "CYGWIN" OR CMAKE_SYSTEM_NAME MATCHES "MSYS" OR CMAKE_SYSTEM_NAME MATCHES "MINGW")
|
if (CMAKE_SYSTEM_NAME MATCHES "CYGWIN" OR CMAKE_SYSTEM_NAME MATCHES "MSYS" OR CMAKE_SYSTEM_NAME MATCHES "MINGW")
|
||||||
set(CMAKE_CXX_EXTENSIONS ON)
|
set(CMAKE_CXX_EXTENSIONS ON)
|
||||||
endif()
|
endif ()
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
# Set SPDLOG_MASTER_PROJECT to ON if we are building spdlog
|
# Set SPDLOG_MASTER_PROJECT to ON if we are building spdlog
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
# Check if spdlog is being used directly or via add_subdirectory, but allow overriding
|
# Check if spdlog is being used directly or via add_subdirectory, but allow overriding
|
||||||
if(NOT DEFINED SPDLOG_MASTER_PROJECT)
|
if (NOT DEFINED SPDLOG_MASTER_PROJECT)
|
||||||
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
||||||
set(SPDLOG_MASTER_PROJECT ON)
|
set(SPDLOG_MASTER_PROJECT ON)
|
||||||
else()
|
else ()
|
||||||
set(SPDLOG_MASTER_PROJECT OFF)
|
set(SPDLOG_MASTER_PROJECT OFF)
|
||||||
endif()
|
endif ()
|
||||||
endif()
|
endif ()
|
||||||
|
|
||||||
option(SPDLOG_BUILD_ALL "Build all artifacts" OFF)
|
option(SPDLOG_BUILD_ALL "Build all artifacts" OFF)
|
||||||
|
|
||||||
@ -77,11 +77,11 @@ option(SPDLOG_SYSTEM_INCLUDES "Include as system headers (skip for clang-tidy)."
|
|||||||
option(SPDLOG_INSTALL "Generate the install target" ${SPDLOG_MASTER_PROJECT})
|
option(SPDLOG_INSTALL "Generate the install target" ${SPDLOG_MASTER_PROJECT})
|
||||||
option(SPDLOG_FMT_EXTERNAL "Use external fmt library instead of of fetching from gitub." OFF)
|
option(SPDLOG_FMT_EXTERNAL "Use external fmt library instead of of fetching from gitub." OFF)
|
||||||
|
|
||||||
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)
|
||||||
@ -91,18 +91,18 @@ option(SPDLOG_NO_TLS "Disable thread local storage" OFF)
|
|||||||
# clang-tidy
|
# clang-tidy
|
||||||
option(SPDLOG_TIDY "run clang-tidy" OFF)
|
option(SPDLOG_TIDY "run clang-tidy" OFF)
|
||||||
|
|
||||||
if(SPDLOG_TIDY)
|
if (SPDLOG_TIDY)
|
||||||
set(CMAKE_CXX_CLANG_TIDY "clang-tidy")
|
set(CMAKE_CXX_CLANG_TIDY "clang-tidy")
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
message(STATUS "Enabled clang-tidy")
|
message(STATUS "Enabled clang-tidy")
|
||||||
endif()
|
endif ()
|
||||||
|
|
||||||
if(SPDLOG_BUILD_SHARED)
|
if (SPDLOG_BUILD_SHARED)
|
||||||
set(BUILD_SHARED_LIBS ON)
|
set(BUILD_SHARED_LIBS ON)
|
||||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||||
endif()
|
endif ()
|
||||||
|
|
||||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||||
# place dlls and libs and executables in the same directory
|
# place dlls and libs and executables in the same directory
|
||||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>)
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>)
|
||||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>)
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>)
|
||||||
@ -113,7 +113,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
|||||||
add_compile_options(/Zc:__cplusplus)
|
add_compile_options(/Zc:__cplusplus)
|
||||||
# enable parallel build for the solution
|
# enable parallel build for the solution
|
||||||
add_compile_options(/MP)
|
add_compile_options(/MP)
|
||||||
endif()
|
endif ()
|
||||||
|
|
||||||
message(STATUS "spdlog version: ${SPDLOG_VERSION}")
|
message(STATUS "spdlog version: ${SPDLOG_VERSION}")
|
||||||
message(STATUS "spdlog build type: " ${CMAKE_BUILD_TYPE})
|
message(STATUS "spdlog build type: " ${CMAKE_BUILD_TYPE})
|
||||||
@ -123,12 +123,12 @@ message(STATUS "spdlog fmt external: " ${SPDLOG_FMT_EXTERNAL})
|
|||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
# Find {fmt} library
|
# Find {fmt} library
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
if(SPDLOG_FMT_EXTERNAL)
|
if (SPDLOG_FMT_EXTERNAL)
|
||||||
find_package(fmt REQUIRED)
|
find_package(fmt REQUIRED)
|
||||||
message(STATUS "Using external fmt lib version: ${fmt_VERSION}")
|
message(STATUS "Using external fmt lib version: ${fmt_VERSION}")
|
||||||
else()
|
else ()
|
||||||
include(cmake/fmtlib.cmake)
|
include(cmake/fmtlib.cmake)
|
||||||
endif()
|
endif ()
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
# Threads library is required
|
# Threads library is required
|
||||||
@ -139,196 +139,198 @@ find_package(Threads REQUIRED)
|
|||||||
# Library sources
|
# Library sources
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
set(SPDLOG_HEADERS
|
set(SPDLOG_HEADERS
|
||||||
"include/spdlog/common.h"
|
"include/spdlog/common.h"
|
||||||
"include/spdlog/formatter.h"
|
"include/spdlog/formatter.h"
|
||||||
"include/spdlog/fwd.h"
|
"include/spdlog/fwd.h"
|
||||||
"include/spdlog/logger.h"
|
"include/spdlog/logger.h"
|
||||||
"include/spdlog/pattern_formatter.h"
|
"include/spdlog/pattern_formatter.h"
|
||||||
"include/spdlog/source_loc.h"
|
"include/spdlog/source_loc.h"
|
||||||
"include/spdlog/spdlog.h"
|
"include/spdlog/spdlog.h"
|
||||||
"include/spdlog/stopwatch.h"
|
"include/spdlog/stopwatch.h"
|
||||||
"include/spdlog/version.h"
|
"include/spdlog/version.h"
|
||||||
"include/spdlog/details/circular_q.h"
|
"include/spdlog/details/circular_q.h"
|
||||||
"include/spdlog/details/file_helper.h"
|
"include/spdlog/details/file_helper.h"
|
||||||
"include/spdlog/details/fmt_helper.h"
|
"include/spdlog/details/fmt_helper.h"
|
||||||
"include/spdlog/details/log_msg.h"
|
"include/spdlog/details/log_msg.h"
|
||||||
"include/spdlog/details/async_log_msg.h"
|
"include/spdlog/details/async_log_msg.h"
|
||||||
"include/spdlog/details/mpmc_blocking_q.h"
|
"include/spdlog/details/mpmc_blocking_q.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/bin_to_hex.h"
|
"include/spdlog/details/error_handler.h"
|
||||||
"include/spdlog/sinks/android_sink.h"
|
"include/spdlog/bin_to_hex.h"
|
||||||
"include/spdlog/sinks/base_sink.h"
|
"include/spdlog/sinks/android_sink.h"
|
||||||
"include/spdlog/sinks/basic_file_sink.h"
|
"include/spdlog/sinks/base_sink.h"
|
||||||
"include/spdlog/sinks/callback_sink.h"
|
"include/spdlog/sinks/basic_file_sink.h"
|
||||||
"include/spdlog/sinks/daily_file_sink.h"
|
"include/spdlog/sinks/callback_sink.h"
|
||||||
"include/spdlog/sinks/dist_sink.h"
|
"include/spdlog/sinks/daily_file_sink.h"
|
||||||
"include/spdlog/sinks/dup_filter_sink.h"
|
"include/spdlog/sinks/dist_sink.h"
|
||||||
"include/spdlog/sinks/hourly_file_sink.h"
|
"include/spdlog/sinks/dup_filter_sink.h"
|
||||||
"include/spdlog/sinks/kafka_sink.h"
|
"include/spdlog/sinks/hourly_file_sink.h"
|
||||||
"include/spdlog/sinks/mongo_sink.h"
|
"include/spdlog/sinks/kafka_sink.h"
|
||||||
"include/spdlog/sinks/msvc_sink.h"
|
"include/spdlog/sinks/mongo_sink.h"
|
||||||
"include/spdlog/sinks/null_sink.h"
|
"include/spdlog/sinks/msvc_sink.h"
|
||||||
"include/spdlog/sinks/ostream_sink.h"
|
"include/spdlog/sinks/null_sink.h"
|
||||||
"include/spdlog/sinks/qt_sinks.h"
|
"include/spdlog/sinks/ostream_sink.h"
|
||||||
"include/spdlog/sinks/ringbuffer_sink.h"
|
"include/spdlog/sinks/qt_sinks.h"
|
||||||
"include/spdlog/sinks/rotating_file_sink.h"
|
"include/spdlog/sinks/ringbuffer_sink.h"
|
||||||
"include/spdlog/sinks/sink.h"
|
"include/spdlog/sinks/rotating_file_sink.h"
|
||||||
"include/spdlog/sinks/stdout_color_sinks.h"
|
"include/spdlog/sinks/sink.h"
|
||||||
"include/spdlog/sinks/stdout_sinks.h"
|
"include/spdlog/sinks/stdout_color_sinks.h"
|
||||||
"include/spdlog/sinks/syslog_sink.h"
|
"include/spdlog/sinks/stdout_sinks.h"
|
||||||
"include/spdlog/sinks/systemd_sink.h"
|
"include/spdlog/sinks/syslog_sink.h"
|
||||||
"include/spdlog/sinks/tcp_sink.h"
|
"include/spdlog/sinks/systemd_sink.h"
|
||||||
"include/spdlog/sinks/udp_sink.h"
|
"include/spdlog/sinks/tcp_sink.h"
|
||||||
"include/spdlog/sinks/async_sink.h")
|
"include/spdlog/sinks/udp_sink.h"
|
||||||
|
"include/spdlog/sinks/async_sink.h")
|
||||||
|
|
||||||
set(SPDLOG_SRCS
|
set(SPDLOG_SRCS
|
||||||
"src/common.cpp"
|
"src/common.cpp"
|
||||||
"src/logger.cpp"
|
"src/logger.cpp"
|
||||||
"src/pattern_formatter.cpp"
|
"src/pattern_formatter.cpp"
|
||||||
"src/spdlog.cpp"
|
"src/spdlog.cpp"
|
||||||
"src/details/file_helper.cpp"
|
"src/details/file_helper.cpp"
|
||||||
"src/details/os_filesystem.cpp"
|
"src/details/os_filesystem.cpp"
|
||||||
"src/details/log_msg.cpp"
|
"src/details/log_msg.cpp"
|
||||||
"src/details/async_log_msg.cpp"
|
"src/details/async_log_msg.cpp"
|
||||||
|
"src/details/error_handler.cpp"
|
||||||
"src/sinks/base_sink.cpp"
|
"src/sinks/base_sink.cpp"
|
||||||
"src/sinks/basic_file_sink.cpp"
|
"src/sinks/basic_file_sink.cpp"
|
||||||
"src/sinks/rotating_file_sink.cpp"
|
"src/sinks/rotating_file_sink.cpp"
|
||||||
"src/sinks/stdout_sinks.cpp"
|
"src/sinks/stdout_sinks.cpp"
|
||||||
"src/sinks/async_sink.cpp")
|
"src/sinks/async_sink.cpp")
|
||||||
|
|
||||||
if(WIN32)
|
if (WIN32)
|
||||||
list(APPEND SPDLOG_SRCS
|
list(APPEND SPDLOG_SRCS
|
||||||
"src/details/os_windows.cpp"
|
"src/details/os_windows.cpp"
|
||||||
"src/sinks/wincolor_sink.cpp")
|
"src/sinks/wincolor_sink.cpp")
|
||||||
list(APPEND SPDLOG_HEADERS
|
list(APPEND SPDLOG_HEADERS
|
||||||
"include/spdlog/sinks/wincolor_sink.h"
|
"include/spdlog/sinks/wincolor_sink.h"
|
||||||
"include/spdlog/details/tcp_client_windows.h"
|
"include/spdlog/details/tcp_client_windows.h"
|
||||||
"include/spdlog/details/udp_client_windows.h"
|
"include/spdlog/details/udp_client_windows.h"
|
||||||
"include/spdlog/details/windows_include.h"
|
"include/spdlog/details/windows_include.h"
|
||||||
"include/spdlog/sinks/win_eventlog_sink.h")
|
"include/spdlog/sinks/win_eventlog_sink.h")
|
||||||
else()
|
else ()
|
||||||
list(APPEND SPDLOG_SRCS
|
list(APPEND SPDLOG_SRCS
|
||||||
"src/details/os_unix.cpp"
|
"src/details/os_unix.cpp"
|
||||||
"src/sinks/ansicolor_sink.cpp")
|
"src/sinks/ansicolor_sink.cpp")
|
||||||
list(APPEND SPDLOG_HEADERS
|
list(APPEND SPDLOG_HEADERS
|
||||||
"include/spdlog/details/tcp_client_unix.h"
|
"include/spdlog/details/tcp_client_unix.h"
|
||||||
"include/spdlog/details/udp_client_unix.h"
|
"include/spdlog/details/udp_client_unix.h"
|
||||||
"include/spdlog/sinks/ansicolor_sink.h")
|
"include/spdlog/sinks/ansicolor_sink.h")
|
||||||
endif()
|
endif ()
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
# Check if fwrite_unlocked/_fwrite_nolock is available
|
# Check if fwrite_unlocked/_fwrite_nolock is available
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
include(CheckSymbolExists)
|
include(CheckSymbolExists)
|
||||||
if(WIN32)
|
if (WIN32)
|
||||||
check_symbol_exists(_fwrite_nolock "stdio.h" HAVE_FWRITE_UNLOCKED)
|
check_symbol_exists(_fwrite_nolock "stdio.h" HAVE_FWRITE_UNLOCKED)
|
||||||
else()
|
else ()
|
||||||
check_symbol_exists(fwrite_unlocked "stdio.h" HAVE_FWRITE_UNLOCKED)
|
check_symbol_exists(fwrite_unlocked "stdio.h" HAVE_FWRITE_UNLOCKED)
|
||||||
endif()
|
endif ()
|
||||||
if(HAVE_FWRITE_UNLOCKED)
|
if (HAVE_FWRITE_UNLOCKED)
|
||||||
set(SPDLOG_FWRITE_UNLOCKED 1)
|
set(SPDLOG_FWRITE_UNLOCKED 1)
|
||||||
endif()
|
endif ()
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
# spdlog library
|
# spdlog library
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
if(BUILD_SHARED_LIBS)
|
if (BUILD_SHARED_LIBS)
|
||||||
if(WIN32)
|
if (WIN32)
|
||||||
set(VERSION_RC ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
|
set(VERSION_RC ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
|
||||||
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)
|
||||||
endif()
|
endif ()
|
||||||
add_library(spdlog SHARED ${VERSION_RC})
|
add_library(spdlog SHARED ${VERSION_RC})
|
||||||
target_compile_definitions(spdlog PUBLIC SPDLOG_SHARED_LIB)
|
target_compile_definitions(spdlog PUBLIC SPDLOG_SHARED_LIB)
|
||||||
if(MSVC)
|
if (MSVC)
|
||||||
# disable dlls related warnings on msvc
|
# disable dlls related warnings on msvc
|
||||||
target_compile_options(spdlog PUBLIC $<$<AND:$<CXX_COMPILER_ID:MSVC>,$<NOT:$<COMPILE_LANGUAGE:CUDA>>>:/wd4251
|
target_compile_options(spdlog PUBLIC $<$<AND:$<CXX_COMPILER_ID:MSVC>,$<NOT:$<COMPILE_LANGUAGE:CUDA>>>:/wd4251
|
||||||
/wd4275>)
|
/wd4275>)
|
||||||
endif()
|
endif ()
|
||||||
else()
|
else ()
|
||||||
add_library(spdlog STATIC)
|
add_library(spdlog STATIC)
|
||||||
endif()
|
endif ()
|
||||||
add_library(spdlog::spdlog ALIAS spdlog)
|
add_library(spdlog::spdlog ALIAS spdlog)
|
||||||
target_sources(spdlog PRIVATE ${SPDLOG_SRCS})
|
target_sources(spdlog PRIVATE ${SPDLOG_SRCS})
|
||||||
target_sources(
|
target_sources(
|
||||||
spdlog
|
spdlog
|
||||||
PUBLIC FILE_SET pub_headers
|
PUBLIC FILE_SET pub_headers
|
||||||
TYPE HEADERS
|
TYPE HEADERS
|
||||||
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include
|
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||||
FILES ${SPDLOG_HEADERS})
|
FILES ${SPDLOG_HEADERS})
|
||||||
|
|
||||||
set(SPDLOG_INCLUDES_LEVEL "")
|
set(SPDLOG_INCLUDES_LEVEL "")
|
||||||
if(SPDLOG_SYSTEM_INCLUDES)
|
if (SPDLOG_SYSTEM_INCLUDES)
|
||||||
set(SPDLOG_INCLUDES_LEVEL "SYSTEM")
|
set(SPDLOG_INCLUDES_LEVEL "SYSTEM")
|
||||||
endif()
|
endif ()
|
||||||
|
|
||||||
target_include_directories(spdlog ${SPDLOG_INCLUDES_LEVEL} PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
|
target_include_directories(spdlog ${SPDLOG_INCLUDES_LEVEL} PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
|
||||||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
|
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
|
||||||
|
|
||||||
target_link_libraries(spdlog PUBLIC Threads::Threads)
|
target_link_libraries(spdlog PUBLIC Threads::Threads)
|
||||||
target_link_libraries(spdlog PUBLIC fmt::fmt)
|
target_link_libraries(spdlog PUBLIC fmt::fmt)
|
||||||
spdlog_enable_warnings(spdlog)
|
spdlog_enable_warnings(spdlog)
|
||||||
set_target_properties(spdlog PROPERTIES VERSION ${SPDLOG_VERSION} SOVERSION
|
set_target_properties(spdlog PROPERTIES VERSION ${SPDLOG_VERSION} SOVERSION
|
||||||
${SPDLOG_VERSION_MAJOR}.${SPDLOG_VERSION_MINOR})
|
${SPDLOG_VERSION_MAJOR}.${SPDLOG_VERSION_MINOR})
|
||||||
|
|
||||||
set(SPDLOG_NAME spdlog-${SPDLOG_VERSION_MAJOR})
|
set(SPDLOG_NAME spdlog-${SPDLOG_VERSION_MAJOR})
|
||||||
set_target_properties(spdlog PROPERTIES DEBUG_POSTFIX "-${SPDLOG_VERSION_MAJOR}.${SPDLOG_VERSION_MINOR}d")
|
set_target_properties(spdlog PROPERTIES DEBUG_POSTFIX "-${SPDLOG_VERSION_MAJOR}.${SPDLOG_VERSION_MINOR}d")
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
# set source groups for visual studio
|
# set source groups for visual studio
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
if(CMAKE_GENERATOR MATCHES "Visual Studio")
|
if (CMAKE_GENERATOR MATCHES "Visual Studio")
|
||||||
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/include PREFIX include FILES ${SPDLOG_HEADERS})
|
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/include PREFIX include FILES ${SPDLOG_HEADERS})
|
||||||
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/src PREFIX sources FILES ${SPDLOG_SRCS})
|
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/src PREFIX sources FILES ${SPDLOG_SRCS})
|
||||||
source_group(sources FILES ${VERSION_RC})
|
source_group(sources FILES ${VERSION_RC})
|
||||||
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)
|
||||||
endif()
|
endif ()
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
# spdlog private defines according to the options
|
# spdlog private defines according to the options
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
foreach(SPDLOG_OPTION
|
foreach (SPDLOG_OPTION
|
||||||
SPDLOG_CLOCK_COARSE
|
SPDLOG_CLOCK_COARSE
|
||||||
SPDLOG_PREVENT_CHILD_FD
|
SPDLOG_PREVENT_CHILD_FD
|
||||||
SPDLOG_NO_THREAD_ID
|
SPDLOG_NO_THREAD_ID
|
||||||
SPDLOG_DISABLE_GLOBAL_LOGGER
|
SPDLOG_DISABLE_GLOBAL_LOGGER
|
||||||
SPDLOG_NO_TLS
|
SPDLOG_NO_TLS
|
||||||
SPDLOG_FWRITE_UNLOCKED)
|
SPDLOG_FWRITE_UNLOCKED)
|
||||||
if(${SPDLOG_OPTION})
|
if (${SPDLOG_OPTION})
|
||||||
target_compile_definitions(spdlog PRIVATE ${SPDLOG_OPTION})
|
target_compile_definitions(spdlog PRIVATE ${SPDLOG_OPTION})
|
||||||
endif()
|
endif ()
|
||||||
endforeach()
|
endforeach ()
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
# Build binaries
|
# Build binaries
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
if(SPDLOG_BUILD_EXAMPLE OR SPDLOG_BUILD_ALL)
|
if (SPDLOG_BUILD_EXAMPLE 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)
|
||||||
endif()
|
endif ()
|
||||||
|
|
||||||
if(SPDLOG_BUILD_TESTS OR SPDLOG_BUILD_ALL)
|
if (SPDLOG_BUILD_TESTS 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")
|
||||||
@ -341,13 +343,13 @@ if(SPDLOG_INSTALL)
|
|||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
set(installed_include_dir "${CMAKE_INSTALL_INCLUDEDIR}/${SPDLOG_NAME}")
|
set(installed_include_dir "${CMAKE_INSTALL_INCLUDEDIR}/${SPDLOG_NAME}")
|
||||||
install(
|
install(
|
||||||
TARGETS spdlog
|
TARGETS spdlog
|
||||||
EXPORT spdlogTargets
|
EXPORT spdlogTargets
|
||||||
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/${SPDLOG_NAME}"
|
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/${SPDLOG_NAME}"
|
||||||
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}/${SPDLOG_NAME}"
|
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}/${SPDLOG_NAME}"
|
||||||
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}/${SPDLOG_NAME}"
|
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}/${SPDLOG_NAME}"
|
||||||
FILE_SET pub_headers
|
FILE_SET pub_headers
|
||||||
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${SPDLOG_NAME}")
|
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${SPDLOG_NAME}")
|
||||||
message(STATUS "Installing spdlog in ${CMAKE_INSTALL_LIBDIR}/${SPDLOG_NAME}")
|
message(STATUS "Installing spdlog in ${CMAKE_INSTALL_LIBDIR}/${SPDLOG_NAME}")
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
@ -365,4 +367,4 @@ if(SPDLOG_INSTALL)
|
|||||||
# Support creation of installable packages
|
# Support creation of installable packages
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
include(cmake/spdlogCPack.cmake)
|
include(cmake/spdlogCPack.cmake)
|
||||||
endif()
|
endif ()
|
||||||
|
33
include/spdlog/details/error_handler.h
Normal file
33
include/spdlog/details/error_handler.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||||
|
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <mutex>
|
||||||
|
#include "spdlog/common.h"
|
||||||
|
|
||||||
|
// by default, prints the error to stderr. thread safe.
|
||||||
|
namespace spdlog {
|
||||||
|
namespace details {
|
||||||
|
class error_handler {
|
||||||
|
public:
|
||||||
|
explicit error_handler(std::string name);
|
||||||
|
error_handler(const error_handler &);
|
||||||
|
error_handler(error_handler &&) noexcept;
|
||||||
|
// for simplicity allow only construction of this class.
|
||||||
|
// otherwise we need to deal with mutexes and potential deadlocks.
|
||||||
|
error_handler &operator=(const error_handler &) = delete;
|
||||||
|
error_handler &operator=(error_handler &&) = delete;
|
||||||
|
void handle(const source_loc& loc, const std::string &err_msg) const;
|
||||||
|
void set_name(const std::string& name);
|
||||||
|
void set_custom_handler(err_handler handler);
|
||||||
|
|
||||||
|
private:
|
||||||
|
mutable std::mutex mutex_;
|
||||||
|
std::string name_;
|
||||||
|
err_handler custom_handler_ = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}} // namespace spdlog::details
|
@ -20,19 +20,15 @@
|
|||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "details/log_msg.h"
|
#include "details/log_msg.h"
|
||||||
|
#include "details/error_handler.h"
|
||||||
#include "sinks/sink.h"
|
#include "sinks/sink.h"
|
||||||
|
|
||||||
#define SPDLOG_LOGGER_CATCH(location) \
|
#define SPDLOG_LOGGER_CATCH(location) \
|
||||||
catch (const std::exception &ex) { \
|
catch (const std::exception &ex) { \
|
||||||
if (!location.empty()) { \
|
err_handler_.handle(location, ex.what()); \
|
||||||
err_handler_(fmt_lib::format(SPDLOG_FMT_STRING("{} [{}({})]"), ex.what(), location.filename, location.line)); \
|
|
||||||
} else { \
|
|
||||||
err_handler_(ex.what()); \
|
|
||||||
} \
|
|
||||||
} \
|
} \
|
||||||
catch (...) { \
|
catch (...) { \
|
||||||
err_handler_("Rethrowing unknown exception in logger"); \
|
err_handler_.handle(location, "Unknown exception"); \
|
||||||
throw; \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace spdlog {
|
namespace spdlog {
|
||||||
@ -41,13 +37,15 @@ class SPDLOG_API logger {
|
|||||||
public:
|
public:
|
||||||
// Empty logger
|
// Empty logger
|
||||||
explicit logger(std::string name)
|
explicit logger(std::string name)
|
||||||
: name_(std::move(name)) {}
|
: name_(name),
|
||||||
|
err_handler_(std::move(name)) {}
|
||||||
|
|
||||||
// Logger with range on sinks
|
// Logger with range on sinks
|
||||||
template <typename It>
|
template <typename It>
|
||||||
logger(std::string name, It begin, It end)
|
logger(std::string name, It begin, It end)
|
||||||
: name_(std::move(name)),
|
: name_(name),
|
||||||
sinks_(begin, end) {}
|
sinks_(begin, end),
|
||||||
|
err_handler_(std::move(name)) {}
|
||||||
|
|
||||||
// Logger with single sink
|
// Logger with single sink
|
||||||
logger(std::string name, sink_ptr single_sink)
|
logger(std::string name, sink_ptr single_sink)
|
||||||
@ -175,7 +173,7 @@ private:
|
|||||||
std::vector<sink_ptr> sinks_;
|
std::vector<sink_ptr> sinks_;
|
||||||
atomic_level_t level_{level::info};
|
atomic_level_t level_{level::info};
|
||||||
atomic_level_t flush_level_{level::off};
|
atomic_level_t flush_level_{level::off};
|
||||||
err_handler custom_err_handler_{nullptr};
|
details::error_handler err_handler_;
|
||||||
|
|
||||||
// common implementation for after templated public api has been resolved to format string and
|
// common implementation for after templated public api has been resolved to format string and
|
||||||
// args
|
// args
|
||||||
@ -208,9 +206,6 @@ private:
|
|||||||
}
|
}
|
||||||
void flush_();
|
void flush_();
|
||||||
[[nodiscard]] bool should_flush_(const details::log_msg &msg) const;
|
[[nodiscard]] bool should_flush_(const details::log_msg &msg) const;
|
||||||
|
|
||||||
// default handler prints the error to stderr
|
|
||||||
void err_handler_(const std::string &msg);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace spdlog
|
} // namespace spdlog
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "../details/async_log_msg.h"
|
#include "../details/async_log_msg.h"
|
||||||
|
#include "../details/error_handler.h"
|
||||||
#include "sink.h"
|
#include "sink.h"
|
||||||
|
|
||||||
// async_sink is a sink that sends log messages to a dist_sink in a separate thread using a queue.
|
// async_sink is a sink that sends log messages to a dist_sink in a separate thread using a queue.
|
||||||
@ -73,11 +74,11 @@ private:
|
|||||||
void backend_loop_();
|
void backend_loop_();
|
||||||
void backend_log_(const details::log_msg &msg) ;
|
void backend_log_(const details::log_msg &msg) ;
|
||||||
void backend_flush_();
|
void backend_flush_();
|
||||||
void err_handler_(const std::string &msg);
|
|
||||||
|
|
||||||
config config_;
|
config config_;
|
||||||
std::unique_ptr<queue_t> q_;
|
std::unique_ptr<queue_t> q_;
|
||||||
std::thread worker_thread_;
|
std::thread worker_thread_;
|
||||||
|
details::error_handler err_handler_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sinks
|
} // namespace sinks
|
||||||
|
55
src/details/error_handler.cpp
Normal file
55
src/details/error_handler.cpp
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||||
|
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||||
|
|
||||||
|
#include "spdlog/details/error_handler.h"
|
||||||
|
#include "spdlog/details/os.h"
|
||||||
|
#include "iostream"
|
||||||
|
|
||||||
|
namespace spdlog {
|
||||||
|
namespace details {
|
||||||
|
|
||||||
|
error_handler::error_handler(std::string name)
|
||||||
|
: name_(std::move(name)) {}
|
||||||
|
|
||||||
|
error_handler::error_handler(const error_handler &other) {
|
||||||
|
std::lock_guard lk{other.mutex_};
|
||||||
|
name_ = other.name_;
|
||||||
|
custom_handler_ = other.custom_handler_;
|
||||||
|
}
|
||||||
|
|
||||||
|
error_handler::error_handler(error_handler &&other) noexcept {
|
||||||
|
std::lock_guard lk{other.mutex_};
|
||||||
|
name_ = std::move(other.name_);
|
||||||
|
custom_handler_ = std::move(other.custom_handler_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void error_handler::handle(const source_loc &loc, const std::string &err_msg) const {
|
||||||
|
std::lock_guard lk{mutex_};
|
||||||
|
if (custom_handler_) {
|
||||||
|
custom_handler_(err_msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto tm_time = os::localtime();
|
||||||
|
char date_buf[128];
|
||||||
|
std::strftime(date_buf, sizeof(date_buf), "%Y-%m-%d %H:%M:%S", &tm_time);
|
||||||
|
std::string msg;
|
||||||
|
if (loc.empty()) {
|
||||||
|
msg = fmt_lib::format("[*** LOGGING ERROR ***] [{}] [{}] {}\n", date_buf, name_, err_msg);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
msg = fmt_lib::format("[*** LOGGING ERROR ***] [{}({})] [{}] [{}] {}\n", loc.filename, loc.line, date_buf, name_, err_msg);
|
||||||
|
}
|
||||||
|
std::fputs(msg.c_str(), stderr);
|
||||||
|
}
|
||||||
|
void error_handler::set_name(const std::string &name) {
|
||||||
|
std::lock_guard lk{mutex_};
|
||||||
|
name_ = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void error_handler::set_custom_handler(err_handler handler) {
|
||||||
|
std::lock_guard lk{mutex_};
|
||||||
|
custom_handler_ = std::move(handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace details
|
||||||
|
} // namespace spdlog
|
@ -2,9 +2,7 @@
|
|||||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||||
|
|
||||||
#include "spdlog/logger.h"
|
#include "spdlog/logger.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <mutex>
|
|
||||||
|
|
||||||
#include "spdlog/pattern_formatter.h"
|
#include "spdlog/pattern_formatter.h"
|
||||||
#include "spdlog/sinks/sink.h"
|
#include "spdlog/sinks/sink.h"
|
||||||
@ -17,14 +15,14 @@ logger::logger(const logger &other) noexcept
|
|||||||
sinks_(other.sinks_),
|
sinks_(other.sinks_),
|
||||||
level_(other.level_.load(std::memory_order_relaxed)),
|
level_(other.level_.load(std::memory_order_relaxed)),
|
||||||
flush_level_(other.flush_level_.load(std::memory_order_relaxed)),
|
flush_level_(other.flush_level_.load(std::memory_order_relaxed)),
|
||||||
custom_err_handler_(other.custom_err_handler_) {}
|
err_handler_(other.err_handler_) {}
|
||||||
|
|
||||||
logger::logger(logger &&other) noexcept
|
logger::logger(logger &&other) noexcept
|
||||||
: name_(std::move(other.name_)),
|
: name_(std::move(other.name_)),
|
||||||
sinks_(std::move(other.sinks_)),
|
sinks_(std::move(other.sinks_)),
|
||||||
level_(other.level_.load(std::memory_order_relaxed)),
|
level_(other.level_.load(std::memory_order_relaxed)),
|
||||||
flush_level_(other.flush_level_.load(std::memory_order_relaxed)),
|
flush_level_(other.flush_level_.load(std::memory_order_relaxed)),
|
||||||
custom_err_handler_(std::move(other.custom_err_handler_)) {}
|
err_handler_(std::move(other.err_handler_)) {}
|
||||||
|
|
||||||
void logger::set_level(level level) { level_.store(level); }
|
void logger::set_level(level level) { level_.store(level); }
|
||||||
|
|
||||||
@ -62,13 +60,16 @@ const std::vector<sink_ptr> &logger::sinks() const { return sinks_; }
|
|||||||
|
|
||||||
std::vector<sink_ptr> &logger::sinks() { return sinks_; }
|
std::vector<sink_ptr> &logger::sinks() { return sinks_; }
|
||||||
|
|
||||||
// error handler
|
// custom error handler
|
||||||
void logger::set_error_handler(err_handler handler) { custom_err_handler_ = std::move(handler); }
|
void logger::set_error_handler(err_handler handler) {
|
||||||
|
err_handler_.set_custom_handler(std::move(handler));
|
||||||
|
}
|
||||||
|
|
||||||
// create new logger with same sinks and configuration.
|
// create new logger with same sinks and configuration.
|
||||||
std::shared_ptr<logger> logger::clone(std::string logger_name) {
|
std::shared_ptr<logger> logger::clone(std::string logger_name) {
|
||||||
auto cloned = std::make_shared<logger>(*this);
|
auto cloned = std::make_shared<logger>(*this);
|
||||||
cloned->name_ = std::move(logger_name);
|
cloned->name_ = std::move(logger_name);
|
||||||
|
cloned->err_handler_.set_name(cloned->name_);
|
||||||
return cloned;
|
return cloned;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +79,7 @@ void logger::flush_() {
|
|||||||
try {
|
try {
|
||||||
sink->flush();
|
sink->flush();
|
||||||
}
|
}
|
||||||
SPDLOG_LOGGER_CATCH(source_loc())
|
SPDLOG_LOGGER_CATCH(source_loc{})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,20 +88,4 @@ bool logger::should_flush_(const details::log_msg &msg) const {
|
|||||||
return (msg.log_level >= flush_level) && (msg.log_level != level::off);
|
return (msg.log_level >= flush_level) && (msg.log_level != level::off);
|
||||||
}
|
}
|
||||||
|
|
||||||
void logger::err_handler_(const std::string &msg) {
|
|
||||||
if (custom_err_handler_) {
|
|
||||||
custom_err_handler_(msg);
|
|
||||||
} else {
|
|
||||||
using std::chrono::system_clock;
|
|
||||||
auto now = system_clock::now();
|
|
||||||
auto tm_time = details::os::localtime(system_clock::to_time_t(now));
|
|
||||||
char date_buf[64];
|
|
||||||
std::strftime(date_buf, sizeof(date_buf), "%Y-%m-%d %H:%M:%S", &tm_time);
|
|
||||||
#if defined(USING_R) && defined(R_R_H) // if in R environment
|
|
||||||
REprintf("[*** LOG ERROR ***] [%s] [%s] %s\n", date_buf, name().c_str(), msg.c_str());
|
|
||||||
#else
|
|
||||||
std::fprintf(stderr, "[*** LOG ERROR ***] [%s] [%s] %s\n", date_buf, name().c_str(), msg.c_str());
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // namespace spdlog
|
} // namespace spdlog
|
||||||
|
@ -15,7 +15,7 @@ namespace spdlog {
|
|||||||
namespace sinks {
|
namespace sinks {
|
||||||
|
|
||||||
async_sink::async_sink(config async_config)
|
async_sink::async_sink(config async_config)
|
||||||
: config_(std::move(async_config)) {
|
: config_(std::move(async_config)), err_handler_("async_sink") {
|
||||||
if (config_.queue_size == 0 || config_.queue_size > max_queue_size) {
|
if (config_.queue_size == 0 || config_.queue_size > max_queue_size) {
|
||||||
throw spdlog_ex("async_sink: invalid queue size");
|
throw spdlog_ex("async_sink: invalid queue size");
|
||||||
}
|
}
|
||||||
@ -107,7 +107,7 @@ void async_sink::backend_log_(const details::log_msg &msg) {
|
|||||||
try {
|
try {
|
||||||
sink->log(msg);
|
sink->log(msg);
|
||||||
} catch (const std::exception &ex) {
|
} catch (const std::exception &ex) {
|
||||||
err_handler_(std::string("async log failed: ") + ex.what());
|
err_handler_.handle(msg.source, std::string("async log failed: ") + ex.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -118,24 +118,11 @@ void async_sink::backend_flush_() {
|
|||||||
try {
|
try {
|
||||||
sink->flush();
|
sink->flush();
|
||||||
} catch (const std::exception &ex) {
|
} catch (const std::exception &ex) {
|
||||||
err_handler_(std::string("async flush failed: ") + ex.what());
|
err_handler_.handle(source_loc{}, std::string("async flush failed: ") + ex.what());
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
err_handler_("Async flush failed with unknown exception");
|
err_handler_.handle(source_loc{}, "Async flush failed with unknown exception");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void async_sink::err_handler_(const std::string &message) {
|
|
||||||
using std::chrono::system_clock;
|
|
||||||
const auto now = system_clock::now();
|
|
||||||
const auto tm_time = details::os::localtime(system_clock::to_time_t(now));
|
|
||||||
char date_buf[64];
|
|
||||||
std::strftime(date_buf, sizeof(date_buf), "%Y-%m-%d %H:%M:%S", &tm_time);
|
|
||||||
#if defined(USING_R) && defined(R_R_H) // if in R environment
|
|
||||||
REprintf("[*** LOG ERROR ***] [%s] [%s] %s\n", date_buf, name().c_str(), message.c_str());
|
|
||||||
#else
|
|
||||||
std::fprintf(stderr, "[*** LOG ERROR ***] [%s] %s\n", date_buf, message.c_str());
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sinks
|
} // namespace sinks
|
||||||
} // namespace spdlog
|
} // namespace spdlog
|
||||||
|
Loading…
Reference in New Issue
Block a user