From 12bbef308b5ad652ff753ef3fbc59facff386996 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Mon, 6 Aug 2018 22:19:16 +0300 Subject: [PATCH 01/82] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6cf15068..2d9f8143 100644 --- a/README.md +++ b/README.md @@ -240,7 +240,7 @@ void err_handler_example() void syslog_example() { std::string ident = "spdlog-example"; - auto syslog_logger = spdlog::syslog_logger("syslog", ident, LOG_PID); + auto syslog_logger = spdlog::syslog_logger_mt("syslog", ident, LOG_PID); syslog_logger->warn("This is warning that will end up in syslog."); } ``` From 8179b26388d118fa887030f2609560ec287531dd Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Tue, 7 Aug 2018 03:29:45 +0300 Subject: [PATCH 02/82] Update file_log.cpp --- tests/file_log.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/file_log.cpp b/tests/file_log.cpp index ace4c065..9ddaae83 100644 --- a/tests/file_log.cpp +++ b/tests/file_log.cpp @@ -33,7 +33,7 @@ TEST_CASE("flush_on", "[flush_on]]") logger->info("Test message {}", 1); logger->info("Test message {}", 2); - logger->flush(); + REQUIRE(file_contents(filename) == std::string("Should not be flushed\nTest message 1\nTest message 2\n")); REQUIRE(count_lines(filename) == 3); } From a2fa7a833c3898a45755e9c0638286e27f74323c Mon Sep 17 00:00:00 2001 From: baishuai Date: Wed, 8 Aug 2018 22:59:57 +0800 Subject: [PATCH 03/82] add new line at end of file, fix compiler warnings --- include/spdlog/details/circular_q.h | 2 +- include/spdlog/details/fmt_helper.h | 2 +- include/spdlog/details/thread_pool.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/spdlog/details/circular_q.h b/include/spdlog/details/circular_q.h index 48f9a8fa..bfdc657a 100644 --- a/include/spdlog/details/circular_q.h +++ b/include/spdlog/details/circular_q.h @@ -59,4 +59,4 @@ private: std::vector v_; }; } // namespace details -} // namespace spdlog \ No newline at end of file +} // namespace spdlog diff --git a/include/spdlog/details/fmt_helper.h b/include/spdlog/details/fmt_helper.h index 05a41526..da3d8f85 100644 --- a/include/spdlog/details/fmt_helper.h +++ b/include/spdlog/details/fmt_helper.h @@ -138,4 +138,4 @@ inline void pad6(size_t n, fmt::basic_memory_buffer &dest) } // namespace fmt_helper } // namespace details -} // namespace spdlog \ No newline at end of file +} // namespace spdlog diff --git a/include/spdlog/details/thread_pool.h b/include/spdlog/details/thread_pool.h index 4fee130c..6acaf7fa 100644 --- a/include/spdlog/details/thread_pool.h +++ b/include/spdlog/details/thread_pool.h @@ -216,4 +216,4 @@ private: }; } // namespace details -} // namespace spdlog \ No newline at end of file +} // namespace spdlog From 769f11109d65bc076f4e72b5d31d7ce0c348f7f4 Mon Sep 17 00:00:00 2001 From: rajesh-p Date: Thu, 9 Aug 2018 21:17:53 -0700 Subject: [PATCH 04/82] Namespace fix for the issue 785 Added namespace fix --- include/spdlog/sinks/android_sink.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/spdlog/sinks/android_sink.h b/include/spdlog/sinks/android_sink.h index be70db00..d6238600 100644 --- a/include/spdlog/sinks/android_sink.h +++ b/include/spdlog/sinks/android_sink.h @@ -43,11 +43,11 @@ protected: fmt::memory_buffer formatted; if (use_raw_msg_) { - fmt_helper::append_buf(msg.raw, formatted); + details::fmt_helper::append_buf(msg.raw, formatted); } else { - formatter_->format(msg, formatted); + sink::formatter_->format(msg, formatted); } formatted.push_back('\0'); const char *msg_output = formatted.data(); From 7e32ccbd8f634252bdf3bb09c4f25fe5a6587708 Mon Sep 17 00:00:00 2001 From: Daniel Chabrowski Date: Fri, 10 Aug 2018 22:20:52 +0200 Subject: [PATCH 05/82] Modify travis-ci, fix issues Added: * Release/Debug job for gcc 7 and clang 3.5 * Debug asan gcc 7 job * Debug tsan gcc 7 job * Disabled extensions * Added a spdlog::spdlog alias for tests Removed: * Valgrind workaround, the current version is 3.10.1 * install_libcxx * Makefiles Fixed: * examples build * multisink build Workarounds: * gcc7 with tsan and asan needs gold linker, otherwise build fails becase of unrecognized option '--push-state' --- .travis.yml | 202 ++++++++++++++++++++++------------------ CMakeLists.txt | 2 + example/CMakeLists.txt | 12 +-- example/multisink.cpp | 2 +- tests/CMakeLists.txt | 2 +- tests/Makefile | 22 ----- tests/install_libcxx.sh | 12 --- 7 files changed, 118 insertions(+), 136 deletions(-) delete mode 100644 tests/Makefile delete mode 100755 tests/install_libcxx.sh diff --git a/.travis.yml b/.travis.yml index 85273844..2c87f4a8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,91 +1,111 @@ -# Adapted from various sources, including: -# - Louis Dionne's Hana: https://github.com/ldionne/hana -# - Paul Fultz II's FIT: https://github.com/pfultz2/Fit -# - Eric Niebler's range-v3: https://github.com/ericniebler/range-v3 -language: cpp - -# Test matrix: -# - Build matrix per compiler: C++11/C++14 + Debug/Release -# - Optionally: AddressSanitizer (ASAN) -# - Valgrind: all release builds are also tested with valgrind -# - clang 3.4, 3.5, 3.6, trunk -# - Note: 3.4 and trunk are tested with/without ASAN, -# the rest is only tested with ASAN=On. -# - gcc 4.9, 5.0 -# -matrix: - include: - -# Test gcc-4.8: C++11, Build=Debug/Release, ASAN=Off - - env: GCC_VERSION=4.8 BUILD_TYPE=Debug CPP=11 ASAN=Off LIBCXX=Off - os: linux - addons: &gcc48 - apt: - packages: - - g++-4.8 - - valgrind - sources: - - ubuntu-toolchain-r-test - - - env: GCC_VERSION=4.8 BUILD_TYPE=Release CPP=11 ASAN=Off LIBCXX=Off - os: linux - addons: *gcc48 - - # Test gcc-4.9: C++11, Build=Debug/Release, ASAN=Off - - env: GCC_VERSION=4.9 BUILD_TYPE=Debug CPP=11 ASAN=Off LIBCXX=Off - os: linux - addons: &gcc49 - apt: - packages: - - g++-4.9 - - valgrind - sources: - - ubuntu-toolchain-r-test - - - env: GCC_VERSION=4.9 BUILD_TYPE=Release CPP=11 ASAN=Off LIBCXX=Off - os: linux - addons: *gcc49 - -# Install dependencies -before_install: - - export CHECKOUT_PATH=`pwd`; - - if [ -n "$GCC_VERSION" ]; then export CXX="g++-${GCC_VERSION}" CC="gcc-${GCC_VERSION}"; fi - - if [ -n "$CLANG_VERSION" ]; then export CXX="clang++-${CLANG_VERSION}" CC="clang-${CLANG_VERSION}"; fi - - if [ "$CLANG_VERSION" == "3.4" ]; then export CXX="/usr/local/clang-3.4/bin/clang++" CC="/usr/local/clang-3.4/bin/clang"; fi - - which $CXX - - which $CC - - which valgrind - - if [ -n "$CLANG_VERSION" ]; then sudo CXX=$CXX CC=$CC ./tests/install_libcxx.sh; fi - -install: - - cd $CHECKOUT_PATH - - # Workaround for valgrind bug: https://bugs.kde.org/show_bug.cgi?id=326469. - # It is fixed in valgrind 3.10 so this won't be necessary if someone - # replaces the current valgrind (3.7) with valgrind-3.10 - - sed -i 's/march=native/msse4.2/' example/Makefile - - - if [ ! -d build ]; then mkdir build; fi - - export CXX_FLAGS="-I${CHECKOUT_PATH}/include" - - export CXX_LINKER_FLAGS="" - - if [ -z "$BUILD_TYPE" ]; then export BUILD_TYPE=Release; fi - - if [ "$ASAN" == "On"]; then export CXX_FLAGS="${CXX_FLAGS} -fsanitize=address,undefined,integer -fno-omit-frame-pointer -fno-sanitize=unsigned-integer-overflow"; fi - - if [ -n "$CLANG_VERSION" ]; then CXX_FLAGS="${CXX_FLAGS} -D__extern_always_inline=inline"; fi - - if [ "$LIBCXX" == "On" ]; then CXX_FLAGS="${CXX_FLAGS} -stdlib=libc++ -I/usr/include/c++/v1/"; fi - - if [ "$LIBCXX" == "On" ]; then CXX_LINKER_FLAGS="${CXX_FLAGS} -L/usr/lib/ -lc++"; fi - - CXX_FLAGS="${CXX_FLAGS} -std=c++${CPP}" - - # Build examples - - cd example - - if [ "$BUILD_TYPE" == "Release" ]; then make rebuild CXXFLAGS="${CXX_FLAGS} ${CXX_LINKER_FLAGS}" VERBOSE=1; export BIN=example; fi - - if [ "$BUILD_TYPE" == "Debug" ]; then make rebuild debug CXXFLAGS="${CXX_FLAGS} ${CXX_LINKER_FLAGS}" VERBOSE=1; export BIN=example-debug; fi - - -script: - - ./"${BIN}" - - valgrind --trace-children=yes --leak-check=full ./"${BIN}" - - cd $CHECKOUT_PATH/tests; make rebuild; ./tests - - cd $CHECKOUT_PATH/tests; STYLE=printf make rebuild; ./tests - -notifications: - email: false +# Adapted from various sources, including: +# - Louis Dionne's Hana: https://github.com/ldionne/hana +# - Paul Fultz II's FIT: https://github.com/pfultz2/Fit +# - Eric Niebler's range-v3: https://github.com/ericniebler/range-v3 +language: cpp + +addons: &gcc48 + apt: + packages: + - g++-4.8 + - valgrind + sources: + - ubuntu-toolchain-r-test + +addons: &gcc49 + apt: + packages: + - g++-4.9 + - valgrind + sources: + - ubuntu-toolchain-r-test + +addons: &gcc7 + apt: + packages: + - g++-7 + - valgrind + sources: + - ubuntu-toolchain-r-test + +addons: &clang35 + apt: + packages: + - clang-3.5 + - valgrind + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.5 + +matrix: + include: + # Test gcc-4.8: C++11, Build=Debug/Release + - env: GCC_VERSION=4.8 BUILD_TYPE=Debug CPP=11 + os: linux + addons: *gcc48 + + - env: GCC_VERSION=4.8 BUILD_TYPE=Release CPP=11 + os: linux + addons: *gcc48 + + # Test gcc-4.9: C++11, Build=Debug/Release + - env: GCC_VERSION=4.9 BUILD_TYPE=Debug CPP=11 + os: linux + addons: *gcc49 + + - env: GCC_VERSION=4.9 BUILD_TYPE=Release CPP=11 + os: linux + addons: *gcc49 + + # Test gcc-7: C++11, Build=Debug/Release + - env: GCC_VERSION=7 BUILD_TYPE=Debug CPP=11 + os: linux + addons: *gcc7 + + - env: GCC_VERSION=7 BUILD_TYPE=Release CPP=11 + os: linux + addons: *gcc7 + + # Test clang-3.5: C++11, Build=Debug/Release + - env: CLANG_VERSION=3.5 BUILD_TYPE=Debug CPP=11 + os: linux + addons: *clang35 + + - env: CLANG_VERSION=3.5 BUILD_TYPE=Release CPP=11 + os: linux + addons: *clang35 + + # Test gcc-7: C++11, Build=Debug, ASAN=On + - env: GCC_VERSION=7 BUILD_TYPE=Debug CPP=11 ASAN=On + os: linux + addons: *gcc7 + + # Test gcc-7: C++11, Build=Debug, TSAN=On + - env: GCC_VERSION=7 BUILD_TYPE=Debug CPP=11 TSAN=On + os: linux + addons: *gcc7 + +before_install: + - if [ -n "$GCC_VERSION" ]; then export CXX="g++-${GCC_VERSION}" CC="gcc-${GCC_VERSION}"; fi + - if [ -n "$CLANG_VERSION" ]; then export CXX="clang++-${CLANG_VERSION}" CC="clang-${CLANG_VERSION}"; fi + - which $CXX + - which $CC + - which valgrind + - $CXX --version + - cmake --version + - valgrind --version + +install: + - if [ "$ASAN" == "On" ]; then export CXX_FLAGS="${CXX_FLAGS} -fsanitize=address,undefined -fno-omit-frame-pointer -fno-sanitize=signed-integer-overflow -fuse-ld=gold"; fi + - if [ "$TSAN" == "On" ]; then export CXX_FLAGS="${CXX_FLAGS} -fsanitize=thread -fno-omit-frame-pointer -fuse-ld=gold"; fi + - cd ${TRAVIS_BUILD_DIR} + - mkdir -p build && cd build + - cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_CXX_STANDARD=$CPP -DCMAKE_CXX_FLAGS="${CXX_FLAGS}" -DSPDLOG_BUILD_EXAMPLES=ON --warn-uninitialized + - VERBOSE=1 make -j2 + +script: + - if [ "$ASAN" != "On" ] && [ "$TSAN" != "On" ]; then CTEST_FLAGS="-DExperimentalMemCheck"; fi + - ctest -j2 -VV $CTEST_FLAGS + +notifications: + email: false diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d55b8ef..6a821129 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,7 @@ include(GNUInstallDirs) #--------------------------------------------------------------------------------------- set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") set(CMAKE_CXX_FLAGS "-Wall -O3 ${CMAKE_CXX_FLAGS}") @@ -23,6 +24,7 @@ endif() # spdlog target #--------------------------------------------------------------------------------------- add_library(spdlog INTERFACE) +add_library(spdlog::spdlog ALIAS spdlog) option(SPDLOG_BUILD_EXAMPLES "Build examples" OFF) cmake_dependent_option(SPDLOG_BUILD_TESTING diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index cc699729..11dc2d98 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -24,10 +24,7 @@ cmake_minimum_required(VERSION 3.1) project(SpdlogExamples CXX) -if(TARGET spdlog) - # Part of the main project - add_library(spdlog::spdlog ALIAS spdlog) -else() +if(NOT TARGET spdlog) # Stand-alone build find_package(spdlog CONFIG REQUIRED) endif() @@ -37,13 +34,10 @@ find_package(Threads REQUIRED) add_executable(example example.cpp) target_link_libraries(example spdlog::spdlog Threads::Threads) -add_executable(benchmark bench.cpp) -target_link_libraries(benchmark spdlog::spdlog Threads::Threads) - add_executable(multisink multisink.cpp) target_link_libraries(multisink spdlog::spdlog Threads::Threads) enable_testing() file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs") -add_test(NAME RunExample COMMAND example) -add_test(NAME RunBenchmark COMMAND benchmark) +add_test(NAME example COMMAND example) +add_test(NAME multisink COMMAND multisink) diff --git a/example/multisink.cpp b/example/multisink.cpp index 4b3f2d9c..fefa3b39 100644 --- a/example/multisink.cpp +++ b/example/multisink.cpp @@ -1,4 +1,4 @@ -#include "spdlog/sinks/file_sinks.h" +#include "spdlog/sinks/basic_file_sink.h" #include "spdlog/sinks/stdout_sinks.h" #include "spdlog/spdlog.h" #include diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ba8b7487..18af9770 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -18,7 +18,7 @@ set(SPDLOG_UTESTS_SOURCES add_executable(${PROJECT_NAME} ${SPDLOG_UTESTS_SOURCES}) target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads) -target_link_libraries(${PROJECT_NAME} PRIVATE spdlog) +target_link_libraries(${PROJECT_NAME} PRIVATE spdlog::spdlog) add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME}) file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs") diff --git a/tests/Makefile b/tests/Makefile deleted file mode 100644 index 00c7c589..00000000 --- a/tests/Makefile +++ /dev/null @@ -1,22 +0,0 @@ -CXX ?= g++ -CXXFLAGS = -Wall -pedantic -std=c++11 -pthread -O3 -I../include -fmax-errors=1 -LDPFALGS = -pthread - -CPP_FILES := $(wildcard *.cpp) -OBJ_FILES := $(addprefix ./,$(notdir $(CPP_FILES:.cpp=.o))) - - -tests: $(OBJ_FILES) - $(CXX) $(CXXFLAGS) $(LDPFALGS) -o $@ $^ - mkdir -p logs - -%.o: %.cpp - $(CXX) $(CXXFLAGS) -c -o $@ $< - -clean: - rm -f tests *.o logs/*.txt - -rebuild: clean tests - - - diff --git a/tests/install_libcxx.sh b/tests/install_libcxx.sh deleted file mode 100755 index cee97692..00000000 --- a/tests/install_libcxx.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -# -# Install libc++ under travis - -svn --quiet co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx -mkdir libcxx/build -(cd libcxx/build && cmake .. -DLIBCXX_CXX_ABI=libstdc++ -DLIBCXX_CXX_ABI_INCLUDE_PATHS="/usr/include/c++/4.6;/usr/include/c++/4.6/x86_64-linux-gnu") -make -C libcxx/build cxx -j2 -sudo cp libcxx/build/lib/libc++.so.1.0 /usr/lib/ -sudo cp -r libcxx/build/include/c++/v1 /usr/include/c++/v1/ -sudo ln -sf /usr/lib/libc++.so.1.0 /usr/lib/libc++.so -sudo ln -sf /usr/lib/libc++.so.1.0 /usr/lib/libc++.so.1 From 49d663f6c8001af5277cc4b63584f439934a684c Mon Sep 17 00:00:00 2001 From: Daniel Chabrowski Date: Sun, 12 Aug 2018 14:32:07 +0200 Subject: [PATCH 06/82] Move tsan/asan flag management to cmake Add sudo: required to fix asan builds --- .travis.yml | 13 ++++++++++--- CMakeLists.txt | 2 ++ cmake/sanitizers.cmake | 21 +++++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 cmake/sanitizers.cmake diff --git a/.travis.yml b/.travis.yml index 2c87f4a8..811d0503 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ # - Louis Dionne's Hana: https://github.com/ldionne/hana # - Paul Fultz II's FIT: https://github.com/pfultz2/Fit # - Eric Niebler's range-v3: https://github.com/ericniebler/range-v3 +sudo: required language: cpp addons: &gcc48 @@ -96,14 +97,20 @@ before_install: - valgrind --version install: - - if [ "$ASAN" == "On" ]; then export CXX_FLAGS="${CXX_FLAGS} -fsanitize=address,undefined -fno-omit-frame-pointer -fno-sanitize=signed-integer-overflow -fuse-ld=gold"; fi - - if [ "$TSAN" == "On" ]; then export CXX_FLAGS="${CXX_FLAGS} -fsanitize=thread -fno-omit-frame-pointer -fuse-ld=gold"; fi - cd ${TRAVIS_BUILD_DIR} - mkdir -p build && cd build - - cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_CXX_STANDARD=$CPP -DCMAKE_CXX_FLAGS="${CXX_FLAGS}" -DSPDLOG_BUILD_EXAMPLES=ON --warn-uninitialized + - | + cmake .. \ + --warn-uninitialized \ + -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ + -DCMAKE_CXX_STANDARD=$CPP \ + -DSPDLOG_BUILD_EXAMPLES=ON \ + -DSPDLOG_SANITIZE_THREAD=$TSAN \ + -DSPDLOG_SANITIZE_ADDRESS=$ASAN - VERBOSE=1 make -j2 script: + - export TSAN_OPTIONS=verbosity=1 - if [ "$ASAN" != "On" ] && [ "$TSAN" != "On" ]; then CTEST_FLAGS="-DExperimentalMemCheck"; fi - ctest -j2 -VV $CTEST_FLAGS diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a821129..a5cceb70 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,8 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCH set(CMAKE_CXX_FLAGS "-Wall -O3 ${CMAKE_CXX_FLAGS}") endif() +include(cmake/sanitizers.cmake) + #--------------------------------------------------------------------------------------- # spdlog target #--------------------------------------------------------------------------------------- diff --git a/cmake/sanitizers.cmake b/cmake/sanitizers.cmake new file mode 100644 index 00000000..3b090835 --- /dev/null +++ b/cmake/sanitizers.cmake @@ -0,0 +1,21 @@ +if(SPDLOG_SANITIZE_THREAD AND SPDLOG_SANITIZE_ADDRESS) + message(FATAL_ERROR "AddressSanitizer is not compatible with ThreadSanitizer.") +endif() + +if(SPDLOG_SANITIZE_ADDRESS) + message(STATUS "AddressSanitizer enabled") + set(SANITIZER_FLAGS "-fsanitize=address,undefined") + add_compile_options("-fno-sanitize=signed-integer-overflow") +endif() + +if(SPDLOG_SANITIZE_THREAD) + message(STATUS "ThreadSanitizer enabled") + set(SANITIZER_FLAGS "-fsanitize=thread") +endif() + +if(SPDLOG_SANITIZE_THREAD OR SPDLOG_SANITIZE_ADDRESS) + add_compile_options(${SANITIZER_FLAGS}) + add_compile_options("-fno-sanitize-recover=all") + add_compile_options("-fno-omit-frame-pointer") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${SANITIZER_FLAGS} -fuse-ld=gold") +endif() From 368b3699d01be0e73aaa055aef0fc3a4efea68a6 Mon Sep 17 00:00:00 2001 From: Daniel Chabrowski Date: Sun, 12 Aug 2018 18:41:39 +0200 Subject: [PATCH 07/82] Run ASAN/TSAN jobs with clang Bring back removed tests/Makefile --- .travis.yml | 20 ++++++++++++++------ tests/Makefile | 22 ++++++++++++++++++++++ 2 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 tests/Makefile diff --git a/.travis.yml b/.travis.yml index 811d0503..dfd1fca8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,6 +38,14 @@ addons: &clang35 - ubuntu-toolchain-r-test - llvm-toolchain-precise-3.5 +addons: &clang6 + apt: + packages: + - clang-6.0 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-trusty-6.0 + matrix: include: # Test gcc-4.8: C++11, Build=Debug/Release @@ -76,15 +84,15 @@ matrix: os: linux addons: *clang35 - # Test gcc-7: C++11, Build=Debug, ASAN=On - - env: GCC_VERSION=7 BUILD_TYPE=Debug CPP=11 ASAN=On + # Test clang-6.0: C++11, Build=Debug, ASAN=On + - env: CLANG_VERSION=6.0 BUILD_TYPE=Debug CPP=11 ASAN=On os: linux - addons: *gcc7 + addons: *clang6 - # Test gcc-7: C++11, Build=Debug, TSAN=On - - env: GCC_VERSION=7 BUILD_TYPE=Debug CPP=11 TSAN=On + # Test clang-6.0: C++11, Build=Debug, TSAN=On + - env: CLANG_VERSION=6.0 BUILD_TYPE=Debug CPP=11 TSAN=On os: linux - addons: *gcc7 + addons: *clang6 before_install: - if [ -n "$GCC_VERSION" ]; then export CXX="g++-${GCC_VERSION}" CC="gcc-${GCC_VERSION}"; fi diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 00000000..00c7c589 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,22 @@ +CXX ?= g++ +CXXFLAGS = -Wall -pedantic -std=c++11 -pthread -O3 -I../include -fmax-errors=1 +LDPFALGS = -pthread + +CPP_FILES := $(wildcard *.cpp) +OBJ_FILES := $(addprefix ./,$(notdir $(CPP_FILES:.cpp=.o))) + + +tests: $(OBJ_FILES) + $(CXX) $(CXXFLAGS) $(LDPFALGS) -o $@ $^ + mkdir -p logs + +%.o: %.cpp + $(CXX) $(CXXFLAGS) -c -o $@ $< + +clean: + rm -f tests *.o logs/*.txt + +rebuild: clean tests + + + From af5a516443f82f797b0a5752d626e4b045e64301 Mon Sep 17 00:00:00 2001 From: Daniel Chabrowski Date: Sun, 12 Aug 2018 18:51:34 +0200 Subject: [PATCH 08/82] Add valgrind to a clang6 addon Unfortunately valgrind is required for all addons --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index dfd1fca8..bc1f6982 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,6 +42,7 @@ addons: &clang6 apt: packages: - clang-6.0 + - valgrind sources: - ubuntu-toolchain-r-test - llvm-toolchain-trusty-6.0 From 4534d5239fe5dac44af1cd6c9b276224ff5379af Mon Sep 17 00:00:00 2001 From: Daniel Chabrowski Date: Sun, 12 Aug 2018 20:34:30 +0200 Subject: [PATCH 09/82] Remove tsan and gcc 4.9 jobs --- .travis.yml | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/.travis.yml b/.travis.yml index bc1f6982..3067c322 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,14 +13,6 @@ addons: &gcc48 sources: - ubuntu-toolchain-r-test -addons: &gcc49 - apt: - packages: - - g++-4.9 - - valgrind - sources: - - ubuntu-toolchain-r-test - addons: &gcc7 apt: packages: @@ -58,15 +50,6 @@ matrix: os: linux addons: *gcc48 - # Test gcc-4.9: C++11, Build=Debug/Release - - env: GCC_VERSION=4.9 BUILD_TYPE=Debug CPP=11 - os: linux - addons: *gcc49 - - - env: GCC_VERSION=4.9 BUILD_TYPE=Release CPP=11 - os: linux - addons: *gcc49 - # Test gcc-7: C++11, Build=Debug/Release - env: GCC_VERSION=7 BUILD_TYPE=Debug CPP=11 os: linux @@ -90,11 +73,6 @@ matrix: os: linux addons: *clang6 - # Test clang-6.0: C++11, Build=Debug, TSAN=On - - env: CLANG_VERSION=6.0 BUILD_TYPE=Debug CPP=11 TSAN=On - os: linux - addons: *clang6 - before_install: - if [ -n "$GCC_VERSION" ]; then export CXX="g++-${GCC_VERSION}" CC="gcc-${GCC_VERSION}"; fi - if [ -n "$CLANG_VERSION" ]; then export CXX="clang++-${CLANG_VERSION}" CC="clang-${CLANG_VERSION}"; fi @@ -114,13 +92,11 @@ install: -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ -DCMAKE_CXX_STANDARD=$CPP \ -DSPDLOG_BUILD_EXAMPLES=ON \ - -DSPDLOG_SANITIZE_THREAD=$TSAN \ -DSPDLOG_SANITIZE_ADDRESS=$ASAN - VERBOSE=1 make -j2 script: - - export TSAN_OPTIONS=verbosity=1 - - if [ "$ASAN" != "On" ] && [ "$TSAN" != "On" ]; then CTEST_FLAGS="-DExperimentalMemCheck"; fi + - if [ "$ASAN" != "On" ]; then CTEST_FLAGS="-DExperimentalMemCheck"; fi - ctest -j2 -VV $CTEST_FLAGS notifications: From da30e2ef18da4570227aaa501673afffa097768d Mon Sep 17 00:00:00 2001 From: gabime Date: Mon, 13 Aug 2018 01:22:35 +0300 Subject: [PATCH 10/82] Improved CMakeLists and added bench --- .travis.yml | 2 +- CMakeLists.txt | 25 ++++++++++++++++++++++-- bench/CMakeLists.txt | 44 ++++++++++++++++++++++++++++++++++++++++++ example/CMakeLists.txt | 1 - 4 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 bench/CMakeLists.txt diff --git a/.travis.yml b/.travis.yml index 3067c322..80c30db9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -93,7 +93,7 @@ install: -DCMAKE_CXX_STANDARD=$CPP \ -DSPDLOG_BUILD_EXAMPLES=ON \ -DSPDLOG_SANITIZE_ADDRESS=$ASAN - - VERBOSE=1 make -j2 + - make VERBOSE=1-j2 script: - if [ "$ASAN" != "On" ]; then CTEST_FLAGS="-DExperimentalMemCheck"; fi diff --git a/CMakeLists.txt b/CMakeLists.txt index a5cceb70..5166d39f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,17 @@ include(CTest) include(CMakeDependentOption) include(GNUInstallDirs) +#--------------------------------------------------------------------------------------- +# set default build to release +#--------------------------------------------------------------------------------------- +if (NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose Release or Debug" FORCE) +endif() + +message("Build type: " ${CMAKE_BUILD_TYPE}) + + + #--------------------------------------------------------------------------------------- # compiler config #--------------------------------------------------------------------------------------- @@ -17,9 +28,13 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") - set(CMAKE_CXX_FLAGS "-Wall -O3 ${CMAKE_CXX_FLAGS}") + set(CMAKE_CXX_FLAGS "-Wall -Wextra ${CMAKE_CXX_FLAGS}") endif() + +#--------------------------------------------------------------------------------------- +# address sanitizers check +#--------------------------------------------------------------------------------------- include(cmake/sanitizers.cmake) #--------------------------------------------------------------------------------------- @@ -28,7 +43,9 @@ include(cmake/sanitizers.cmake) add_library(spdlog INTERFACE) add_library(spdlog::spdlog ALIAS spdlog) -option(SPDLOG_BUILD_EXAMPLES "Build examples" OFF) +option(SPDLOG_BUILD_EXAMPLES "Build examples" ON) +option(SPDLOG_BUILD_BENCH "Build benchmarks" ON) + cmake_dependent_option(SPDLOG_BUILD_TESTING "Build spdlog tests" ON "BUILD_TESTING" OFF @@ -51,6 +68,10 @@ if(SPDLOG_BUILD_TESTING) add_subdirectory(tests) endif() +if(SPDLOG_BUILD_BENCH) + add_subdirectory(bench) +endif() + #--------------------------------------------------------------------------------------- # Install/export targets and files #--------------------------------------------------------------------------------------- diff --git a/bench/CMakeLists.txt b/bench/CMakeLists.txt new file mode 100644 index 00000000..9f596d27 --- /dev/null +++ b/bench/CMakeLists.txt @@ -0,0 +1,44 @@ +# *************************************************************************/ +# * Copyright (c) 2015 Ruslan Baratov. */ +# * */ +# * Permission is hereby granted, free of charge, to any person obtaining */ +# * a copy of this software and associated documentation files (the */ +# * "Software"), to deal in the Software without restriction, including */ +# * without limitation the rights to use, copy, modify, merge, publish, */ +# * distribute, sublicense, and/or sell copies of the Software, and to */ +# * permit persons to whom the Software is furnished to do so, subject to */ +# * the following conditions: */ +# * */ +# * The above copyright notice and this permission notice shall be */ +# * included in all copies or substantial portions of the Software. */ +# * */ +# * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +# * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +# * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +# * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +# * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +# * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +# * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +# *************************************************************************/ + +cmake_minimum_required(VERSION 3.1) +project(SpdlogBench CXX) + +if(NOT TARGET spdlog) + # Stand-alone build + find_package(spdlog CONFIG REQUIRED) +endif() + +find_package(Threads REQUIRED) + +add_executable(bench bench.cpp) +target_link_libraries(bench spdlog::spdlog Threads::Threads) + +add_executable(async_bench async_bench.cpp) +target_link_libraries(async_bench spdlog::spdlog Threads::Threads) + +add_executable(latency latency.cpp) +target_link_libraries(latency spdlog::spdlog Threads::Threads) + +file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs") + diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 11dc2d98..69eb374e 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -40,4 +40,3 @@ target_link_libraries(multisink spdlog::spdlog Threads::Threads) enable_testing() file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs") add_test(NAME example COMMAND example) -add_test(NAME multisink COMMAND multisink) From d951ea32a675bf01744f04a193e75880e3b6b018 Mon Sep 17 00:00:00 2001 From: gabime Date: Mon, 13 Aug 2018 01:44:10 +0300 Subject: [PATCH 11/82] travis improvments --- .travis.yml | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 80c30db9..c3574a7b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -76,12 +76,6 @@ matrix: before_install: - if [ -n "$GCC_VERSION" ]; then export CXX="g++-${GCC_VERSION}" CC="gcc-${GCC_VERSION}"; fi - if [ -n "$CLANG_VERSION" ]; then export CXX="clang++-${CLANG_VERSION}" CC="clang-${CLANG_VERSION}"; fi - - which $CXX - - which $CC - - which valgrind - - $CXX --version - - cmake --version - - valgrind --version install: - cd ${TRAVIS_BUILD_DIR} @@ -92,12 +86,20 @@ install: -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ -DCMAKE_CXX_STANDARD=$CPP \ -DSPDLOG_BUILD_EXAMPLES=ON \ + -DSPDLOG_BUILD_BENCH=OFF \ -DSPDLOG_SANITIZE_ADDRESS=$ASAN - - make VERBOSE=1-j2 + - make VERBOSE=1 -j2 -script: - - if [ "$ASAN" != "On" ]; then CTEST_FLAGS="-DExperimentalMemCheck"; fi - - ctest -j2 -VV $CTEST_FLAGS +before_script: + - which $CXX + - which $CC + - which valgrind + - $CXX --version + - cmake --version + - valgrind --version + +script: + - ctest -j2 --output-on-failure notifications: email: false From 387ccae7d8d0c5449907d3997cd567c16d2e0a5d Mon Sep 17 00:00:00 2001 From: gabime Date: Mon, 13 Aug 2018 01:59:49 +0300 Subject: [PATCH 12/82] Removed gcc7 debug from travis --- .travis.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index c3574a7b..99de31a9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,12 +49,7 @@ matrix: - env: GCC_VERSION=4.8 BUILD_TYPE=Release CPP=11 os: linux addons: *gcc48 - - # Test gcc-7: C++11, Build=Debug/Release - - env: GCC_VERSION=7 BUILD_TYPE=Debug CPP=11 - os: linux - addons: *gcc7 - + - env: GCC_VERSION=7 BUILD_TYPE=Release CPP=11 os: linux addons: *gcc7 From 0a585092dc6728f6d49b32f889b0ba4defc31c27 Mon Sep 17 00:00:00 2001 From: gabime Date: Mon, 13 Aug 2018 02:02:17 +0300 Subject: [PATCH 13/82] Added ASAN test in release build to travis --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 99de31a9..8884e9e0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -67,6 +67,10 @@ matrix: - env: CLANG_VERSION=6.0 BUILD_TYPE=Debug CPP=11 ASAN=On os: linux addons: *clang6 + + - env: CLANG_VERSION=6.0 BUILD_TYPE=Release CPP=11 ASAN=On + os: linux + addons: *clang6 before_install: - if [ -n "$GCC_VERSION" ]; then export CXX="g++-${GCC_VERSION}" CC="gcc-${GCC_VERSION}"; fi From 8008d7fe534a899f82cf8b64475c35cc2061911c Mon Sep 17 00:00:00 2001 From: gabime Date: Mon, 13 Aug 2018 09:09:49 +0300 Subject: [PATCH 14/82] Replace emplace_back with push_back in pattern_formatter --- CMakeLists.txt | 2 +- bench/CMakeLists.txt | 8 ++- include/spdlog/details/pattern_formatter.h | 73 +++++++++++----------- include/spdlog/version.h | 2 +- 4 files changed, 46 insertions(+), 39 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5166d39f..b9319d17 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ # cmake_minimum_required(VERSION 3.1) -project(spdlog VERSION 1.0.0 LANGUAGES CXX) +project(spdlog VERSION 1.0.1 LANGUAGES CXX) include(CTest) include(CMakeDependentOption) include(GNUInstallDirs) diff --git a/bench/CMakeLists.txt b/bench/CMakeLists.txt index 9f596d27..0eb25eb2 100644 --- a/bench/CMakeLists.txt +++ b/bench/CMakeLists.txt @@ -24,6 +24,10 @@ cmake_minimum_required(VERSION 3.1) project(SpdlogBench CXX) +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +endif() + if(NOT TARGET spdlog) # Stand-alone build find_package(spdlog CONFIG REQUIRED) @@ -32,7 +36,7 @@ endif() find_package(Threads REQUIRED) add_executable(bench bench.cpp) -target_link_libraries(bench spdlog::spdlog Threads::Threads) +target_link_libraries(bench spdlog::spdlog Threads::Threads -flto) add_executable(async_bench async_bench.cpp) target_link_libraries(async_bench spdlog::spdlog Threads::Threads) @@ -40,5 +44,7 @@ target_link_libraries(async_bench spdlog::spdlog Threads::Threads) add_executable(latency latency.cpp) target_link_libraries(latency spdlog::spdlog Threads::Threads) + + file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs") diff --git a/include/spdlog/details/pattern_formatter.h b/include/spdlog/details/pattern_formatter.h index 765f9305..855ea0d8 100644 --- a/include/spdlog/details/pattern_formatter.h +++ b/include/spdlog/details/pattern_formatter.h @@ -545,7 +545,7 @@ public: pattern_formatter(const pattern_formatter &other) = delete; pattern_formatter &operator=(const pattern_formatter &other) = delete; - virtual std::unique_ptr clone() const override + std::unique_ptr clone() const override { return std::unique_ptr(new pattern_formatter(pattern_, pattern_time_type_, eol_)); } @@ -588,145 +588,146 @@ private: void handle_flag_(char flag) { + using flag_formatter_ptr = std::unique_ptr; switch (flag) { // logger name case 'n': - formatters_.emplace_back(new details::name_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::name_formatter())); break; case 'l': - formatters_.emplace_back(new details::level_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::level_formatter())); break; case 'L': - formatters_.emplace_back(new details::short_level_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::short_level_formatter())); break; case ('t'): - formatters_.emplace_back(new details::t_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::t_formatter())); break; case ('v'): - formatters_.emplace_back(new details::v_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::v_formatter())); break; case ('a'): - formatters_.emplace_back(new details::a_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::a_formatter())); break; case ('A'): - formatters_.emplace_back(new details::A_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::A_formatter())); break; case ('b'): case ('h'): - formatters_.emplace_back(new details::b_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::b_formatter())); break; case ('B'): - formatters_.emplace_back(new details::B_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::B_formatter())); break; case ('c'): - formatters_.emplace_back(new details::c_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::c_formatter())); break; case ('C'): - formatters_.emplace_back(new details::C_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::C_formatter())); break; case ('Y'): - formatters_.emplace_back(new details::Y_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::Y_formatter())); break; case ('D'): case ('x'): - formatters_.emplace_back(new details::D_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::D_formatter())); break; case ('m'): - formatters_.emplace_back(new details::m_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::m_formatter())); break; case ('d'): - formatters_.emplace_back(new details::d_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::d_formatter())); break; case ('H'): - formatters_.emplace_back(new details::H_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::H_formatter())); break; case ('I'): - formatters_.emplace_back(new details::I_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::I_formatter())); break; case ('M'): - formatters_.emplace_back(new details::M_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::M_formatter())); break; case ('S'): - formatters_.emplace_back(new details::S_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::S_formatter())); break; case ('e'): - formatters_.emplace_back(new details::e_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::e_formatter())); break; case ('f'): - formatters_.emplace_back(new details::f_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::f_formatter())); break; case ('F'): - formatters_.emplace_back(new details::F_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::F_formatter())); break; case ('E'): - formatters_.emplace_back(new details::E_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::E_formatter())); break; case ('p'): - formatters_.emplace_back(new details::p_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::p_formatter())); break; case ('r'): - formatters_.emplace_back(new details::r_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::r_formatter())); break; case ('R'): - formatters_.emplace_back(new details::R_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::R_formatter())); break; case ('T'): case ('X'): - formatters_.emplace_back(new details::T_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::T_formatter())); break; case ('z'): - formatters_.emplace_back(new details::z_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::z_formatter())); break; case ('+'): - formatters_.emplace_back(new details::full_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::full_formatter())); break; case ('P'): - formatters_.emplace_back(new details::pid_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::pid_formatter())); break; case ('i'): - formatters_.emplace_back(new details::i_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::i_formatter())); break; case ('^'): - formatters_.emplace_back(new details::color_start_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::color_start_formatter())); break; case ('$'): - formatters_.emplace_back(new details::color_stop_formatter()); + formatters_.push_back(flag_formatter_ptr(new details::color_stop_formatter())); break; default: // Unknown flag appears as is - formatters_.emplace_back(new details::ch_formatter('%')); - formatters_.emplace_back(new details::ch_formatter(flag)); + formatters_.push_back(flag_formatter_ptr(new details::ch_formatter('%'))); + formatters_.push_back(flag_formatter_ptr(new details::ch_formatter(flag))); break; } } diff --git a/include/spdlog/version.h b/include/spdlog/version.h index 729fcba0..87d0b3e8 100644 --- a/include/spdlog/version.h +++ b/include/spdlog/version.h @@ -7,6 +7,6 @@ #define SPDLOG_VER_MAJOR 1 #define SPDLOG_VER_MINOR 0 -#define SPDLOG_VER_PATCH 0 +#define SPDLOG_VER_PATCH 1 #define SPDLOG_VERSION (SPDLOG_VER_MAJOR * 10000 + SPDLOG_VER_MINOR * 100 + SPDLOG_VER_PATCH) From 4456f96ae3973c9c5195621380d9fb3d2ed717f7 Mon Sep 17 00:00:00 2001 From: gabime Date: Mon, 13 Aug 2018 09:21:47 +0300 Subject: [PATCH 15/82] Fixed clang warnings --- include/spdlog/async.h | 2 +- include/spdlog/sinks/android_sink.h | 4 ++-- include/spdlog/sinks/ansicolor_sink.h | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/include/spdlog/async.h b/include/spdlog/async.h index f70c4a3e..b67c3329 100644 --- a/include/spdlog/async.h +++ b/include/spdlog/async.h @@ -42,7 +42,7 @@ struct async_factory_impl auto ®istry_inst = details::registry::instance(); // create global thread pool if not already exists.. - std::lock_guard(registry_inst.tp_mutex()); + std::lock_guard lock(registry_inst.tp_mutex()); auto tp = registry_inst.get_tp(); if (tp == nullptr) { diff --git a/include/spdlog/sinks/android_sink.h b/include/spdlog/sinks/android_sink.h index d6238600..fcb9ccbf 100644 --- a/include/spdlog/sinks/android_sink.h +++ b/include/spdlog/sinks/android_sink.h @@ -30,8 +30,8 @@ template class android_sink SPDLOG_FINAL : public base_sink { public: - explicit android_sink(const std::string &tag = "spdlog", bool use_raw_msg = false) - : tag_(tag) + explicit android_sink(std::string tag = "spdlog", bool use_raw_msg = false) + : tag_(std::move(tag)) , use_raw_msg_(use_raw_msg) { } diff --git a/include/spdlog/sinks/ansicolor_sink.h b/include/spdlog/sinks/ansicolor_sink.h index 3b79976d..4bd1c679 100644 --- a/include/spdlog/sinks/ansicolor_sink.h +++ b/include/spdlog/sinks/ansicolor_sink.h @@ -84,8 +84,7 @@ public: const std::string on_cyan = "\033[46m"; const std::string on_white = "\033[47m"; - void log(const details::log_msg &msg) SPDLOG_FINAL override - { + void log(const details::log_msg &msg) SPDLOG_FINAL { // Wrap the originally formatted message in color codes. // If color is not supported in the terminal, log as is instead. std::lock_guard lock(mutex_); From 4866f2ac059ab9a85e8e024b330ce3df66f6a43f Mon Sep 17 00:00:00 2001 From: gabime Date: Mon, 13 Aug 2018 09:27:11 +0300 Subject: [PATCH 16/82] Put override kw again --- include/spdlog/sinks/ansicolor_sink.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/spdlog/sinks/ansicolor_sink.h b/include/spdlog/sinks/ansicolor_sink.h index 4bd1c679..3b79976d 100644 --- a/include/spdlog/sinks/ansicolor_sink.h +++ b/include/spdlog/sinks/ansicolor_sink.h @@ -84,7 +84,8 @@ public: const std::string on_cyan = "\033[46m"; const std::string on_white = "\033[47m"; - void log(const details::log_msg &msg) SPDLOG_FINAL { + void log(const details::log_msg &msg) SPDLOG_FINAL override + { // Wrap the originally formatted message in color codes. // If color is not supported in the terminal, log as is instead. std::lock_guard lock(mutex_); From 05d6960ebc7a0aa1a32aafa7c64df45086a97775 Mon Sep 17 00:00:00 2001 From: gabime Date: Mon, 13 Aug 2018 10:30:02 +0300 Subject: [PATCH 17/82] code formatting and clang tidy warnings fixes --- README.md | 2 +- include/spdlog/async.h | 2 +- include/spdlog/async_logger.h | 2 +- include/spdlog/common.h | 4 ++-- include/spdlog/details/async_logger_impl.h | 2 +- include/spdlog/details/console_globals.h | 6 +++--- include/spdlog/details/pattern_formatter.h | 5 ++--- include/spdlog/details/periodic_worker.h | 2 +- include/spdlog/details/registry.h | 12 ++++-------- include/spdlog/details/thread_pool.h | 2 +- include/spdlog/sinks/base_sink.h | 2 +- include/spdlog/sinks/sink.h | 2 +- include/spdlog/sinks/stdout_sinks.h | 8 ++++---- include/spdlog/sinks/syslog_sink.h | 4 ++-- include/spdlog/spdlog.h | 6 +++--- tests/file_log.cpp | 2 +- 16 files changed, 29 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 2d9f8143..3b3afba4 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Very fast, header only, C++ logging library. [![Build Status](https://travis-ci. ## Features * Very fast - performance is the primary goal (see [benchmarks](#benchmarks) below). * Headers only, just copy and use. -* Feature rich [call style](#usage-example) using the excellent [fmt](https://github.com/fmtlib/fmt) library. +* Feature rich using the excellent [fmt](https://github.com/fmtlib/fmt) library. * Fast asynchronous mode (optional) * [Custom](https://github.com/gabime/spdlog/wiki/3.-Custom-formatting) formatting. * Conditional Logging diff --git a/include/spdlog/async.h b/include/spdlog/async.h index b67c3329..9c3e9551 100644 --- a/include/spdlog/async.h +++ b/include/spdlog/async.h @@ -42,7 +42,7 @@ struct async_factory_impl auto ®istry_inst = details::registry::instance(); // create global thread pool if not already exists.. - std::lock_guard lock(registry_inst.tp_mutex()); + std::lock_guard tp_lock(registry_inst.tp_mutex()); auto tp = registry_inst.get_tp(); if (tp == nullptr) { diff --git a/include/spdlog/async_logger.h b/include/spdlog/async_logger.h index 2d58f98b..3250f4ad 100644 --- a/include/spdlog/async_logger.h +++ b/include/spdlog/async_logger.h @@ -49,7 +49,7 @@ public: async_logger(std::string logger_name, const It &begin, const It &end, std::weak_ptr tp, async_overflow_policy overflow_policy = async_overflow_policy::block); - async_logger(std::string logger_name, sinks_init_list sinks, std::weak_ptr tp, + async_logger(std::string logger_name, sinks_init_list sinks_list, std::weak_ptr tp, async_overflow_policy overflow_policy = async_overflow_policy::block); async_logger(std::string logger_name, sink_ptr single_sink, std::weak_ptr tp, diff --git a/include/spdlog/common.h b/include/spdlog/common.h index b8d45175..ddb0d28c 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -138,8 +138,8 @@ public: : runtime_error(msg) { } - spdlog_ex(std::string msg, int last_errno) - : runtime_error(std::move(msg)) + spdlog_ex(const std::string &msg, int last_errno) + : runtime_error(msg) , last_errno_(last_errno) { } diff --git a/include/spdlog/details/async_logger_impl.h b/include/spdlog/details/async_logger_impl.h index a42ade94..47659ddc 100644 --- a/include/spdlog/details/async_logger_impl.h +++ b/include/spdlog/details/async_logger_impl.h @@ -47,7 +47,7 @@ inline void spdlog::async_logger::sink_it_(details::log_msg &msg) } else { - throw spdlog_ex("async log: thread pool doens't exist anymore"); + throw spdlog_ex("async log: thread pool doesn't exist anymore"); } } diff --git a/include/spdlog/details/console_globals.h b/include/spdlog/details/console_globals.h index 52de06a5..4ac7f743 100644 --- a/include/spdlog/details/console_globals.h +++ b/include/spdlog/details/console_globals.h @@ -5,14 +5,14 @@ // #include "spdlog/details/null_mutex.h" -#include "stdio.h" +#include #include namespace spdlog { namespace details { struct console_stdout { - static FILE *stream() + static std::FILE *stream() { return stdout; } @@ -26,7 +26,7 @@ struct console_stdout struct console_stderr { - static FILE *stream() + static std::FILE *stream() { return stderr; } diff --git a/include/spdlog/details/pattern_formatter.h b/include/spdlog/details/pattern_formatter.h index 855ea0d8..dd352ae5 100644 --- a/include/spdlog/details/pattern_formatter.h +++ b/include/spdlog/details/pattern_formatter.h @@ -69,7 +69,7 @@ static const char *ampm(const tm &t) return t.tm_hour >= 12 ? "PM" : "AM"; } -static unsigned int to12h(const tm &t) +static int to12h(const tm &t) { return t.tm_hour > 12 ? t.tm_hour - 12 : t.tm_hour; } @@ -242,7 +242,7 @@ class f_formatter SPDLOG_FINAL : public flag_formatter void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override { auto micros = fmt_helper::time_fraction(msg.time); - fmt_helper::pad6(static_cast(micros.count()), dest); + fmt_helper::pad6(static_cast(micros.count()), dest); } }; @@ -745,7 +745,6 @@ private: { formatters_.push_back(std::move(user_chars)); } - // if( if (++it != end) { handle_flag_(*it); diff --git a/include/spdlog/details/periodic_worker.h b/include/spdlog/details/periodic_worker.h index acc13117..57e5fa77 100644 --- a/include/spdlog/details/periodic_worker.h +++ b/include/spdlog/details/periodic_worker.h @@ -23,7 +23,7 @@ namespace details { class periodic_worker { public: - periodic_worker(std::function callback_fun, std::chrono::seconds interval) + periodic_worker(const std::function &callback_fun, std::chrono::seconds interval) { active_ = (interval > std::chrono::seconds::zero()); if (!active_) diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/registry.h index b3db19a2..adbfd16d 100644 --- a/include/spdlog/details/registry.h +++ b/include/spdlog/details/registry.h @@ -35,7 +35,7 @@ public: std::lock_guard lock(logger_map_mutex_); auto logger_name = new_logger->name(); throw_if_exists_(logger_name); - loggers_[logger_name] = new_logger; + loggers_[logger_name] = std::move(new_logger); } void register_and_init(std::shared_ptr new_logger) @@ -56,7 +56,7 @@ public: new_logger->flush_on(flush_level_); // add to registry - loggers_[logger_name] = new_logger; + loggers_[logger_name] = std::move(new_logger); } std::shared_ptr get(const std::string &logger_name) @@ -126,7 +126,7 @@ public: err_handler_ = handler; } - void apply_all(std::function)> fun) + void apply_all(const std::function)> &fun) { std::lock_guard lock(logger_map_mutex_); for (auto &l : loggers_) @@ -189,11 +189,7 @@ private: { } - ~registry() - { - /*std::lock_guard lock(flusher_mutex_); - periodic_flusher_.reset();*/ - } + ~registry() = default; void throw_if_exists_(const std::string &logger_name) { diff --git a/include/spdlog/details/thread_pool.h b/include/spdlog/details/thread_pool.h index 36c056a6..b45b6d2b 100644 --- a/include/spdlog/details/thread_pool.h +++ b/include/spdlog/details/thread_pool.h @@ -122,7 +122,7 @@ public: } for (size_t i = 0; i < threads_n; i++) { - threads_.emplace_back(std::bind(&thread_pool::worker_loop_, this)); + threads_.emplace_back(&thread_pool::worker_loop_, this); } } diff --git a/include/spdlog/sinks/base_sink.h b/include/spdlog/sinks/base_sink.h index 5a3821bc..43863eae 100644 --- a/include/spdlog/sinks/base_sink.h +++ b/include/spdlog/sinks/base_sink.h @@ -30,7 +30,7 @@ public: base_sink(const base_sink &) = delete; base_sink &operator=(const base_sink &) = delete; - void log(const details::log_msg &msg) SPDLOG_FINAL override + void log(const details::log_msg &msg) SPDLOG_FINAL { std::lock_guard lock(mutex_); sink_it_(msg); diff --git a/include/spdlog/sinks/sink.h b/include/spdlog/sinks/sink.h index 288d5438..cb8aecb4 100644 --- a/include/spdlog/sinks/sink.h +++ b/include/spdlog/sinks/sink.h @@ -20,7 +20,7 @@ public: { } - sink(std::unique_ptr formatter) + explicit sink(std::unique_ptr formatter) : level_(level::trace) , formatter_(std::move(formatter)){}; diff --git a/include/spdlog/sinks/stdout_sinks.h b/include/spdlog/sinks/stdout_sinks.h index 64c0ab70..e12739c1 100644 --- a/include/spdlog/sinks/stdout_sinks.h +++ b/include/spdlog/sinks/stdout_sinks.h @@ -19,7 +19,7 @@ namespace spdlog { namespace sinks { template -class stdout_sink : public sink +class stdout_sink SPDLOG_FINAL : public sink { public: using mutex_t = typename ConsoleMutex::mutex_t; @@ -28,7 +28,7 @@ public: , file_(TargetStream::stream()) { } - ~stdout_sink() = default; + ~stdout_sink() override = default; stdout_sink(const stdout_sink &other) = delete; stdout_sink &operator=(const stdout_sink &other) = delete; @@ -48,13 +48,13 @@ public: fflush(file_); } - void set_pattern(const std::string &pattern) override SPDLOG_FINAL + void set_pattern(const std::string &pattern) override { std::lock_guard lock(mutex_); formatter_ = std::unique_ptr(new pattern_formatter(pattern)); } - void set_formatter(std::unique_ptr sink_formatter) override SPDLOG_FINAL + void set_formatter(std::unique_ptr sink_formatter) override { std::lock_guard lock(mutex_); formatter_ = std::move(sink_formatter); diff --git a/include/spdlog/sinks/syslog_sink.h b/include/spdlog/sinks/syslog_sink.h index e171bf9a..151e7a11 100644 --- a/include/spdlog/sinks/syslog_sink.h +++ b/include/spdlog/sinks/syslog_sink.h @@ -24,8 +24,8 @@ class syslog_sink : public base_sink { public: // - syslog_sink(const std::string &ident = "", int syslog_option = 0, int syslog_facility = LOG_USER) - : ident_(ident) + explicit syslog_sink(std::string ident = "", int syslog_option = 0, int syslog_facility = LOG_USER) + : ident_(std::move(ident)) { priorities_[static_cast(level::trace)] = LOG_DEBUG; priorities_[static_cast(level::debug)] = LOG_DEBUG; diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index 2963a2a0..40640ab9 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -64,7 +64,7 @@ inline void set_formatter(std::unique_ptr formatter) // example: spdlog::set_pattern("%Y-%m-%d %H:%M:%S.%e %l : %v"); inline void set_pattern(std::string pattern, pattern_time_type time_type = pattern_time_type::local) { - set_formatter(std::unique_ptr(new pattern_formatter(pattern, time_type))); + set_formatter(std::unique_ptr(new pattern_formatter(std::move(pattern), time_type))); } // Set global logging level @@ -101,9 +101,9 @@ inline void register_logger(std::shared_ptr logger) // Apply a user defined function on all registered loggers // Example: // spdlog::apply_all([&](std::shared_ptr l) {l->flush();}); -inline void apply_all(std::function)> fun) +inline void apply_all(const std::function)> &fun) { - details::registry::instance().apply_all(std::move(fun)); + details::registry::instance().apply_all(fun); } // Drop the reference to the given logger diff --git a/tests/file_log.cpp b/tests/file_log.cpp index 9ddaae83..6a4d7aee 100644 --- a/tests/file_log.cpp +++ b/tests/file_log.cpp @@ -33,7 +33,7 @@ TEST_CASE("flush_on", "[flush_on]]") logger->info("Test message {}", 1); logger->info("Test message {}", 2); - + REQUIRE(file_contents(filename) == std::string("Should not be flushed\nTest message 1\nTest message 2\n")); REQUIRE(count_lines(filename) == 3); } From 6ae240c0b6366459b25e564d96d1f98b6952c72b Mon Sep 17 00:00:00 2001 From: gabime Date: Mon, 13 Aug 2018 10:32:07 +0300 Subject: [PATCH 18/82] code formatting and clang tidy warnings fixes --- include/spdlog/sinks/ansicolor_sink.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/spdlog/sinks/ansicolor_sink.h b/include/spdlog/sinks/ansicolor_sink.h index 3b79976d..3f6c63b6 100644 --- a/include/spdlog/sinks/ansicolor_sink.h +++ b/include/spdlog/sinks/ansicolor_sink.h @@ -24,7 +24,7 @@ namespace sinks { * If no color terminal detected, omit the escape codes. */ template -class ansicolor_sink : public sink +class ansicolor_sink SPDLOG_FINAL : public sink { public: using mutex_t = typename ConsoleMutex::mutex_t; @@ -84,7 +84,7 @@ public: const std::string on_cyan = "\033[46m"; const std::string on_white = "\033[47m"; - void log(const details::log_msg &msg) SPDLOG_FINAL override + void log(const details::log_msg &msg) override { // Wrap the originally formatted message in color codes. // If color is not supported in the terminal, log as is instead. @@ -110,19 +110,19 @@ public: fflush(target_file_); } - void flush() SPDLOG_FINAL override + void flush() override { std::lock_guard lock(mutex_); fflush(target_file_); } - void set_pattern(const std::string &pattern) override SPDLOG_FINAL + void set_pattern(const std::string &pattern) SPDLOG_FINAL { std::lock_guard lock(mutex_); formatter_ = std::unique_ptr(new pattern_formatter(pattern)); } - void set_formatter(std::unique_ptr sink_formatter) override SPDLOG_FINAL + void set_formatter(std::unique_ptr sink_formatter) override { std::lock_guard lock(mutex_); formatter_ = std::move(sink_formatter); From ba337d1393db312dedf41d7b2c4b608e7f4f8a90 Mon Sep 17 00:00:00 2001 From: gabime Date: Mon, 13 Aug 2018 11:16:50 +0300 Subject: [PATCH 19/82] Fixed warning in tests --- tests/registry.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/registry.cpp b/tests/registry.cpp index ff84cacf..9f723272 100644 --- a/tests/registry.cpp +++ b/tests/registry.cpp @@ -33,7 +33,7 @@ TEST_CASE("apply_all" spdlog::register_logger(logger2); int counter = 0; - spdlog::apply_all([&counter](std::shared_ptr l) { counter++; }); + spdlog::apply_all([&counter](std::shared_ptr ) { counter++; }); REQUIRE(counter == 2); counter = 0; From da2af6ea2ed03cedef81c00e6d1c70177d8cc261 Mon Sep 17 00:00:00 2001 From: gabime Date: Mon, 13 Aug 2018 11:43:00 +0300 Subject: [PATCH 20/82] Fixed some clang-tidy warning --- include/spdlog/details/file_helper.h | 2 +- include/spdlog/details/registry.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/spdlog/details/file_helper.h b/include/spdlog/details/file_helper.h index ef70d561..65b3560f 100644 --- a/include/spdlog/details/file_helper.h +++ b/include/spdlog/details/file_helper.h @@ -136,7 +136,7 @@ public: // treat casese like "/etc/rc.d/somelogfile or "/abc/.hiddenfile" auto folder_index = fname.rfind(details::os::folder_sep); - if (folder_index != fname.npos && folder_index >= ext_index - 1) + if (folder_index != filename_t::npos && folder_index >= ext_index - 1) { return std::make_tuple(fname, spdlog::filename_t()); } diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/registry.h index adbfd16d..3988552a 100644 --- a/include/spdlog/details/registry.h +++ b/include/spdlog/details/registry.h @@ -112,7 +112,7 @@ public: void flush_every(std::chrono::seconds interval) { std::lock_guard lock(flusher_mutex_); - std::function clbk(std::bind(®istry::flush_all, this)); + std::function clbk = std::bind(®istry::flush_all, this); periodic_flusher_.reset(new periodic_worker(clbk, interval)); } From 607779cccfcc52ca10145f0b2d7f7e2d0bf16001 Mon Sep 17 00:00:00 2001 From: gabime Date: Mon, 13 Aug 2018 12:27:11 +0300 Subject: [PATCH 21/82] micro optimization in log_msg constructor --- include/spdlog/details/log_msg.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/spdlog/details/log_msg.h b/include/spdlog/details/log_msg.h index ce988e4f..3272dd5d 100644 --- a/include/spdlog/details/log_msg.h +++ b/include/spdlog/details/log_msg.h @@ -16,17 +16,18 @@ namespace details { struct log_msg { log_msg() = default; + log_msg(const std::string *loggers_name, level::level_enum lvl) : logger_name(loggers_name) , level(lvl) - { #ifndef SPDLOG_NO_DATETIME - time = os::now(); + , time(os::now()) #endif #ifndef SPDLOG_NO_THREAD_ID - thread_id = os::thread_id(); + , thread_id(os::thread_id()) #endif + { } log_msg(const log_msg &other) = delete; From aefde13858fc712600c384f0879dc7b4baaab83b Mon Sep 17 00:00:00 2001 From: gabime Date: Mon, 13 Aug 2018 12:27:25 +0300 Subject: [PATCH 22/82] formatting --- tests/registry.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/registry.cpp b/tests/registry.cpp index 9f723272..0c581bc0 100644 --- a/tests/registry.cpp +++ b/tests/registry.cpp @@ -33,7 +33,7 @@ TEST_CASE("apply_all" spdlog::register_logger(logger2); int counter = 0; - spdlog::apply_all([&counter](std::shared_ptr ) { counter++; }); + spdlog::apply_all([&counter](std::shared_ptr) { counter++; }); REQUIRE(counter == 2); counter = 0; From 1d672d39cf0ea62a4f441cad820c4b471b2c6f2b Mon Sep 17 00:00:00 2001 From: gabime Date: Mon, 13 Aug 2018 12:33:58 +0300 Subject: [PATCH 23/82] Udpated README --- README.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3b3afba4..1f8cc97f 100644 --- a/README.md +++ b/README.md @@ -181,7 +181,7 @@ void async_example() ``` --- -#### Logger with multi targets - each with different format and log level +#### Logger with multi sinks - each with different format and log level ```c++ // create logger with 2 targets with different log levels and formats. @@ -201,6 +201,22 @@ void multi_sink_example() logger.info("this message should not appear in the console, only in the file"); } ``` + +--- +#### Async logger with multi sinks +```c++ +// create asynchronous logger with 2 sinks. +void multi_sink_example2() +{ + spdlog::init_thread_pool(8192, 1); + auto stdout_sink = std::make_shared(); + auto rotating_sink = std::make_shared("mylog.txt", 1024*1024*10, 3); + std::vector sinks {stdout_sink, rotating_sink}; + auto logger = std::make_shared("loggername", sinks.begin(), sinks.end(), spdlog::thread_pool(), spdlog::async_overflow_policy::block); + spdlog::register_logger(logger); +} +``` + --- #### User defined types ```c++ From d6cc5847fa3bd9b13fb8d36916d2dd85fd3dfefe Mon Sep 17 00:00:00 2001 From: gabime Date: Mon, 13 Aug 2018 12:37:15 +0300 Subject: [PATCH 24/82] Udpated README --- README.md | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 1f8cc97f..af04f85a 100644 --- a/README.md +++ b/README.md @@ -166,20 +166,7 @@ spdlog::flush_every(std::chrono::seconds(3)); ``` ---- -#### Asynchronous logging -```c++ -#include "spdlog/async.h" -void async_example() -{ - // default thread pool settings can be modified *before* creating the async logger: - // spdlog::init_thread_pool(8192, 1); // queue with 8k items and 1 backing thread. - auto async_file = spdlog::basic_logger_mt("async_file_logger", "logs/async_log.txt"); - // alternatively: - // auto async_file = spdlog::create_async("async_file_logger", "logs/async_log.txt"); -} -``` --- #### Logger with multi sinks - each with different format and log level ```c++ @@ -203,9 +190,29 @@ void multi_sink_example() ``` --- -#### Async logger with multi sinks +#### Asynchronous logging +```c++ +#include "spdlog/async.h" +#include "spdlog/sinks/basic_file_sink.h" +void async_example() +{ + // default thread pool settings can be modified *before* creating the async logger: + // spdlog::init_thread_pool(8192, 1); // queue with 8k items and 1 backing thread. + auto async_file = spdlog::basic_logger_mt("async_file_logger", "logs/async_log.txt"); + // alternatively: + // auto async_file = spdlog::create_async("async_file_logger", "logs/async_log.txt"); +} + +``` + +--- +#### Asynchronous logger with multi sinks ```c++ // create asynchronous logger with 2 sinks. + +#include "spdlog/sinks/stdout_color_sinks.h" +#include "spdlog/sinks/rotating_file_sink.h" + void multi_sink_example2() { spdlog::init_thread_pool(8192, 1); From 56b3a17e569709a2465a290134b104f8e6c16adc Mon Sep 17 00:00:00 2001 From: gabime Date: Mon, 13 Aug 2018 12:38:36 +0300 Subject: [PATCH 25/82] Udpated README --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index af04f85a..e5963703 100644 --- a/README.md +++ b/README.md @@ -208,8 +208,6 @@ void async_example() --- #### Asynchronous logger with multi sinks ```c++ -// create asynchronous logger with 2 sinks. - #include "spdlog/sinks/stdout_color_sinks.h" #include "spdlog/sinks/rotating_file_sink.h" From 566df7e8267e2dbf6c21ef1f2ef97ff7f8e66daa Mon Sep 17 00:00:00 2001 From: gabime Date: Tue, 14 Aug 2018 00:58:09 +0300 Subject: [PATCH 26/82] Added missing include to q --- include/spdlog/details/circular_q.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/spdlog/details/circular_q.h b/include/spdlog/details/circular_q.h index bfdc657a..6f3433a2 100644 --- a/include/spdlog/details/circular_q.h +++ b/include/spdlog/details/circular_q.h @@ -6,6 +6,8 @@ // cirucal q view of std::vector. #pragma once +#include + namespace spdlog { namespace details { template From 530e209f660bb2ba96541111ab9eec0987f4a35d Mon Sep 17 00:00:00 2001 From: gabime Date: Tue, 14 Aug 2018 00:58:50 +0300 Subject: [PATCH 27/82] Fixed async tests to pass TASN checks --- tests/test_async.cpp | 16 ++++++++++------ tests/test_sink.h | 2 ++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/test_async.cpp b/tests/test_async.cpp index 112fede7..c4324df4 100644 --- a/tests/test_async.cpp +++ b/tests/test_async.cpp @@ -26,8 +26,9 @@ TEST_CASE("discard policy ", "[async]") { using namespace spdlog; auto test_sink = std::make_shared(); - size_t queue_size = 2; - size_t messages = 10240; + test_sink->set_delay(std::chrono::milliseconds(1)); + size_t queue_size = 4; + size_t messages = 1024; auto tp = std::make_shared(queue_size, 1); auto logger = std::make_shared("as", test_sink, tp, async_overflow_policy::overrun_oldest); @@ -41,17 +42,20 @@ TEST_CASE("discard policy ", "[async]") TEST_CASE("discard policy using factory ", "[async]") { using namespace spdlog; - size_t queue_size = 2; - size_t messages = 10240; + size_t queue_size = 4; + size_t messages = 1024; spdlog::init_thread_pool(queue_size, 1); auto logger = spdlog::create_async_nb("as2"); + auto test_sink = std::static_pointer_cast(logger->sinks()[0]); + test_sink->set_delay(std::chrono::milliseconds(1)); + for (size_t i = 0; i < messages; i++) { logger->info("Hello message"); } - auto sink = std::static_pointer_cast(logger->sinks()[0]); - REQUIRE(sink->msg_counter() < messages); + + REQUIRE(test_sink->msg_counter() < messages); spdlog::drop_all(); } diff --git a/tests/test_sink.h b/tests/test_sink.h index 101c15f1..ae08e980 100644 --- a/tests/test_sink.h +++ b/tests/test_sink.h @@ -21,11 +21,13 @@ class test_sink : public base_sink public: size_t msg_counter() { + std::lock_guard lock(base_sink::mutex_); return msg_counter_; } size_t flush_counter() { + std::lock_guard lock(base_sink::mutex_); return flush_counter_; } From dca20731a2ea360ae1ac7f1e4935f1ee31ac843a Mon Sep 17 00:00:00 2001 From: gabime Date: Tue, 14 Aug 2018 01:02:05 +0300 Subject: [PATCH 28/82] Added thread sanitizer tests to travis CI --- .travis.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8884e9e0..e21cb131 100644 --- a/.travis.yml +++ b/.travis.yml @@ -71,6 +71,16 @@ matrix: - env: CLANG_VERSION=6.0 BUILD_TYPE=Release CPP=11 ASAN=On os: linux addons: *clang6 + + # Test clang-6.0: C++11, Build=Debug, TSAN=On + - env: CLANG_VERSION=6.0 BUILD_TYPE=Debug CPP=11 TSAN=On + os: linux + addons: *clang6 + + - env: CLANG_VERSION=6.0 BUILD_TYPE=Release CPP=11 TSAN=On + os: linux + addons: *clang6 + before_install: - if [ -n "$GCC_VERSION" ]; then export CXX="g++-${GCC_VERSION}" CC="gcc-${GCC_VERSION}"; fi @@ -86,7 +96,8 @@ install: -DCMAKE_CXX_STANDARD=$CPP \ -DSPDLOG_BUILD_EXAMPLES=ON \ -DSPDLOG_BUILD_BENCH=OFF \ - -DSPDLOG_SANITIZE_ADDRESS=$ASAN + -DSPDLOG_SANITIZE_ADDRESS=$ASAN \ + -DSPDLOG_SANITIZE_THREAD=$ASAN - make VERBOSE=1 -j2 before_script: From 08064716b350954cab56ab45c9100a4aee9324ca Mon Sep 17 00:00:00 2001 From: gabime Date: Tue, 14 Aug 2018 01:05:16 +0300 Subject: [PATCH 29/82] Fixed cmake for bench --- bench/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench/CMakeLists.txt b/bench/CMakeLists.txt index 0eb25eb2..946b762a 100644 --- a/bench/CMakeLists.txt +++ b/bench/CMakeLists.txt @@ -36,7 +36,7 @@ endif() find_package(Threads REQUIRED) add_executable(bench bench.cpp) -target_link_libraries(bench spdlog::spdlog Threads::Threads -flto) +target_link_libraries(bench spdlog::spdlog Threads::Threads) add_executable(async_bench async_bench.cpp) target_link_libraries(async_bench spdlog::spdlog Threads::Threads) From cb0d8cfbbddc01c53b14d71c475c089c1f55d27c Mon Sep 17 00:00:00 2001 From: gabime Date: Tue, 14 Aug 2018 01:15:39 +0300 Subject: [PATCH 30/82] Fixed travis --- .travis.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index e21cb131..53511930 100644 --- a/.travis.yml +++ b/.travis.yml @@ -64,20 +64,20 @@ matrix: addons: *clang35 # Test clang-6.0: C++11, Build=Debug, ASAN=On - - env: CLANG_VERSION=6.0 BUILD_TYPE=Debug CPP=11 ASAN=On + - env: CLANG_VERSION=6.0 BUILD_TYPE=Debug CPP=11 ASAN=On TSAN=Off os: linux addons: *clang6 - - env: CLANG_VERSION=6.0 BUILD_TYPE=Release CPP=11 ASAN=On + - env: CLANG_VERSION=6.0 BUILD_TYPE=Release CPP=11 ASAN=On TSAN=Off os: linux addons: *clang6 # Test clang-6.0: C++11, Build=Debug, TSAN=On - - env: CLANG_VERSION=6.0 BUILD_TYPE=Debug CPP=11 TSAN=On + - env: CLANG_VERSION=6.0 BUILD_TYPE=Debug CPP=11 ASAN=Off TSAN=On os: linux addons: *clang6 - - env: CLANG_VERSION=6.0 BUILD_TYPE=Release CPP=11 TSAN=On + - env: CLANG_VERSION=6.0 BUILD_TYPE=Release CPP=11 ASAN=Off TSAN=On os: linux addons: *clang6 @@ -97,7 +97,7 @@ install: -DSPDLOG_BUILD_EXAMPLES=ON \ -DSPDLOG_BUILD_BENCH=OFF \ -DSPDLOG_SANITIZE_ADDRESS=$ASAN \ - -DSPDLOG_SANITIZE_THREAD=$ASAN + -DSPDLOG_SANITIZE_THREAD=$TSAN - make VERBOSE=1 -j2 before_script: From 1dba3162c4cade394ee49de92b38866d0cde3053 Mon Sep 17 00:00:00 2001 From: gabime Date: Tue, 14 Aug 2018 01:19:29 +0300 Subject: [PATCH 31/82] Fixed travis --- .travis.yml | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 53511930..b0dbcba7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -82,11 +82,17 @@ matrix: addons: *clang6 -before_install: +before_script: - if [ -n "$GCC_VERSION" ]; then export CXX="g++-${GCC_VERSION}" CC="gcc-${GCC_VERSION}"; fi - if [ -n "$CLANG_VERSION" ]; then export CXX="clang++-${CLANG_VERSION}" CC="clang-${CLANG_VERSION}"; fi + - which $CXX + - which $CC + - which valgrind + - $CXX --version + - cmake --version + - valgrind --version -install: +script: - cd ${TRAVIS_BUILD_DIR} - mkdir -p build && cd build - | @@ -98,18 +104,10 @@ install: -DSPDLOG_BUILD_BENCH=OFF \ -DSPDLOG_SANITIZE_ADDRESS=$ASAN \ -DSPDLOG_SANITIZE_THREAD=$TSAN - - make VERBOSE=1 -j2 - -before_script: - - which $CXX - - which $CC - - which valgrind - - $CXX --version - - cmake --version - - valgrind --version - -script: + - make VERBOSE=1 -j2 - ctest -j2 --output-on-failure + + notifications: email: false From 70f3ed66f4785641c31c68b0d827d7da5c55c355 Mon Sep 17 00:00:00 2001 From: gabime Date: Tue, 14 Aug 2018 01:46:57 +0300 Subject: [PATCH 32/82] Update readme --- README.md | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index e5963703..241d3fbd 100644 --- a/README.md +++ b/README.md @@ -53,27 +53,28 @@ Below are some [benchmarks](https://github.com/gabime/spdlog/blob/v1.x/bench/ben ******************************************************************************* Single thread, 1,000,000 iterations ******************************************************************************* -basic_st... Elapsed: 0.231041 4,328,228/sec -rotating... Elapsed: 0.233466 4,283,282/sec -daily_st... Elapsed: 0.244491 4,090,136/sec -null_st... Elapsed: 0.162708 6,145,995/sec +basic_st... Elapsed: 0.226664 4,411,806/sec +rotating_st... Elapsed: 0.214339 4,665,499/sec +daily_st... Elapsed: 0.211292 4,732,797/sec +null_st... Elapsed: 0.102815 9,726,227/sec ******************************************************************************* 10 threads sharing same logger, 1,000,000 iterations ******************************************************************************* -basic_mt... Elapsed: 0.854029 1,170,920/sec -rotating_mt Elapsed: 0.867038 1,153,351/sec -daily_mt... Elapsed: 0.869593 1,149,963/sec -null_mt... Elapsed: 0.171215 2,033,537/sec -``` +basic_mt... Elapsed: 0.882268 1,133,441/sec +rotating_mt... Elapsed: 0.875515 1,142,184/sec +daily_mt... Elapsed: 0.879573 1,136,915/sec +null_mt... Elapsed: 0.220114 4,543,105/sec +``` #### Asynchronous mode ``` ******************************************************************************* 10 threads sharing same logger, 1,000,000 iterations ******************************************************************************* -async... Elapsed: 0.442731 2,258,706/sec -async... Elapsed: 0.427072 2,341,527/sec -async... Elapsed: 0.449768 2,223,369/sec +async... Elapsed: 0.429088 2,330,524/sec +async... Elapsed: 0.411501 2,430,126/sec +async... Elapsed: 0.428979 2,331,116/sec + ``` ## Usage samples From 0272bd284642274a0341aaef7237130027883e1a Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Tue, 14 Aug 2018 01:50:09 +0300 Subject: [PATCH 33/82] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 241d3fbd..f6e7ecbf 100644 --- a/README.md +++ b/README.md @@ -54,17 +54,17 @@ Below are some [benchmarks](https://github.com/gabime/spdlog/blob/v1.x/bench/ben Single thread, 1,000,000 iterations ******************************************************************************* basic_st... Elapsed: 0.226664 4,411,806/sec -rotating_st... Elapsed: 0.214339 4,665,499/sec +rotating_st... Elapsed: 0.214339 4,665,499/sec daily_st... Elapsed: 0.211292 4,732,797/sec -null_st... Elapsed: 0.102815 9,726,227/sec +null_st... Elapsed: 0.102815 9,726,227/sec ******************************************************************************* 10 threads sharing same logger, 1,000,000 iterations ******************************************************************************* basic_mt... Elapsed: 0.882268 1,133,441/sec -rotating_mt... Elapsed: 0.875515 1,142,184/sec +rotating_mt... Elapsed: 0.875515 1,142,184/sec daily_mt... Elapsed: 0.879573 1,136,915/sec -null_mt... Elapsed: 0.220114 4,543,105/sec +null_mt... Elapsed: 0.220114 4,543,105/sec ``` #### Asynchronous mode ``` From 54896763abffa37b9bb10dec626d87b99d48f153 Mon Sep 17 00:00:00 2001 From: gabime Date: Tue, 14 Aug 2018 01:51:22 +0300 Subject: [PATCH 34/82] Update readme --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f6e7ecbf..ca797e14 100644 --- a/README.md +++ b/README.md @@ -54,17 +54,17 @@ Below are some [benchmarks](https://github.com/gabime/spdlog/blob/v1.x/bench/ben Single thread, 1,000,000 iterations ******************************************************************************* basic_st... Elapsed: 0.226664 4,411,806/sec -rotating_st... Elapsed: 0.214339 4,665,499/sec +rotating_st... Elapsed: 0.214339 4,665,499/sec daily_st... Elapsed: 0.211292 4,732,797/sec -null_st... Elapsed: 0.102815 9,726,227/sec +null_st... Elapsed: 0.102815 9,726,227/sec ******************************************************************************* 10 threads sharing same logger, 1,000,000 iterations ******************************************************************************* basic_mt... Elapsed: 0.882268 1,133,441/sec -rotating_mt... Elapsed: 0.875515 1,142,184/sec +rotating_mt... Elapsed: 0.875515 1,142,184/sec daily_mt... Elapsed: 0.879573 1,136,915/sec -null_mt... Elapsed: 0.220114 4,543,105/sec +null_mt... Elapsed: 0.220114 4,543,105/sec ``` #### Asynchronous mode ``` From 863f704f479038a1b7f47a5cbb2fe32bd44b922d Mon Sep 17 00:00:00 2001 From: Luiz Siqueira Date: Tue, 14 Aug 2018 08:51:20 -0300 Subject: [PATCH 35/82] increment counter every time we overrid a message in async mode. --- include/spdlog/details/circular_q.h | 8 ++++++++ include/spdlog/details/mpmc_blocking_q.h | 5 +++++ include/spdlog/details/thread_pool.h | 5 +++++ tests/test_async.cpp | 4 ++++ 4 files changed, 22 insertions(+) diff --git a/include/spdlog/details/circular_q.h b/include/spdlog/details/circular_q.h index 6f3433a2..cea12174 100644 --- a/include/spdlog/details/circular_q.h +++ b/include/spdlog/details/circular_q.h @@ -31,6 +31,7 @@ public: if (tail_ == head_) // overrun last item if full { head_ = (head_ + 1) % max_items_; + ++overrun_counter_; } } @@ -53,12 +54,19 @@ public: return ((tail_ + 1) % max_items_) == head_; } + int overrun_counter() const + { + return overrun_counter_; + } + private: size_t max_items_; typename std::vector::size_type head_ = 0; typename std::vector::size_type tail_ = 0; std::vector v_; + + int overrun_counter_ = 0; }; } // namespace details } // namespace spdlog diff --git a/include/spdlog/details/mpmc_blocking_q.h b/include/spdlog/details/mpmc_blocking_q.h index d607da2c..3aa9fa1b 100644 --- a/include/spdlog/details/mpmc_blocking_q.h +++ b/include/spdlog/details/mpmc_blocking_q.h @@ -30,6 +30,11 @@ public: { } + int overrun_counter() const + { + return q_.overrun_counter(); + } + #ifndef __MINGW32__ // try to enqueue and block if no room left void enqueue(T &&item) diff --git a/include/spdlog/details/thread_pool.h b/include/spdlog/details/thread_pool.h index b45b6d2b..fd47eed2 100644 --- a/include/spdlog/details/thread_pool.h +++ b/include/spdlog/details/thread_pool.h @@ -157,6 +157,11 @@ public: post_async_msg_(async_msg(std::move(worker_ptr), async_msg_type::flush), overflow_policy); } + int overrun_counter() const + { + return q_.overrun_counter(); + } + private: q_type q_; diff --git a/tests/test_async.cpp b/tests/test_async.cpp index c4324df4..91be8bd9 100644 --- a/tests/test_async.cpp +++ b/tests/test_async.cpp @@ -7,6 +7,7 @@ TEST_CASE("basic async test ", "[async]") { using namespace spdlog; auto test_sink = std::make_shared(); + int overrun_counter = 0; size_t queue_size = 128; size_t messages = 256; { @@ -17,9 +18,11 @@ TEST_CASE("basic async test ", "[async]") logger->info("Hello message #{}", i); } logger->flush(); + overrun_counter = tp->overrun_counter(); } REQUIRE(test_sink->msg_counter() == messages); REQUIRE(test_sink->flush_counter() == 1); + REQUIRE(overrun_counter == 0); } TEST_CASE("discard policy ", "[async]") @@ -37,6 +40,7 @@ TEST_CASE("discard policy ", "[async]") logger->info("Hello message"); } REQUIRE(test_sink->msg_counter() < messages); + REQUIRE(tp->overrun_counter() > 0); } TEST_CASE("discard policy using factory ", "[async]") From c543985cf4a060c4c038b303c3c8bcc6db13657c Mon Sep 17 00:00:00 2001 From: Luiz Siqueira Date: Tue, 14 Aug 2018 09:21:52 -0300 Subject: [PATCH 36/82] use size_t instead of int for overrun counter --- include/spdlog/details/circular_q.h | 4 ++-- include/spdlog/details/mpmc_blocking_q.h | 2 +- include/spdlog/details/thread_pool.h | 2 +- tests/test_async.cpp | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/spdlog/details/circular_q.h b/include/spdlog/details/circular_q.h index cea12174..b78af247 100644 --- a/include/spdlog/details/circular_q.h +++ b/include/spdlog/details/circular_q.h @@ -54,7 +54,7 @@ public: return ((tail_ + 1) % max_items_) == head_; } - int overrun_counter() const + size_t overrun_counter() const { return overrun_counter_; } @@ -66,7 +66,7 @@ private: std::vector v_; - int overrun_counter_ = 0; + size_t overrun_counter_ = 0; }; } // namespace details } // namespace spdlog diff --git a/include/spdlog/details/mpmc_blocking_q.h b/include/spdlog/details/mpmc_blocking_q.h index 3aa9fa1b..9a922e04 100644 --- a/include/spdlog/details/mpmc_blocking_q.h +++ b/include/spdlog/details/mpmc_blocking_q.h @@ -30,7 +30,7 @@ public: { } - int overrun_counter() const + size_t overrun_counter() const { return q_.overrun_counter(); } diff --git a/include/spdlog/details/thread_pool.h b/include/spdlog/details/thread_pool.h index fd47eed2..aab089f4 100644 --- a/include/spdlog/details/thread_pool.h +++ b/include/spdlog/details/thread_pool.h @@ -157,7 +157,7 @@ public: post_async_msg_(async_msg(std::move(worker_ptr), async_msg_type::flush), overflow_policy); } - int overrun_counter() const + size_t overrun_counter() const { return q_.overrun_counter(); } diff --git a/tests/test_async.cpp b/tests/test_async.cpp index 91be8bd9..6f86cf6c 100644 --- a/tests/test_async.cpp +++ b/tests/test_async.cpp @@ -7,7 +7,7 @@ TEST_CASE("basic async test ", "[async]") { using namespace spdlog; auto test_sink = std::make_shared(); - int overrun_counter = 0; + size_t overrun_counter = 0; size_t queue_size = 128; size_t messages = 256; { From 4eb80dd8d273d4785c780cf10e1bad9433ab8a35 Mon Sep 17 00:00:00 2001 From: Luiz Siqueira Date: Tue, 14 Aug 2018 10:11:03 -0300 Subject: [PATCH 37/82] acquire lock before reading overrun_counter --- include/spdlog/details/mpmc_blocking_q.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/spdlog/details/mpmc_blocking_q.h b/include/spdlog/details/mpmc_blocking_q.h index 9a922e04..cf34d225 100644 --- a/include/spdlog/details/mpmc_blocking_q.h +++ b/include/spdlog/details/mpmc_blocking_q.h @@ -32,6 +32,7 @@ public: size_t overrun_counter() const { + std::unique_lock lock(queue_mutex_); return q_.overrun_counter(); } From 750b520f415458762fa302c246f1f3fd013ccfbe Mon Sep 17 00:00:00 2001 From: gabime Date: Tue, 14 Aug 2018 16:38:35 +0300 Subject: [PATCH 38/82] Fix broken build --- include/spdlog/details/circular_q.h | 2 +- include/spdlog/details/mpmc_blocking_q.h | 12 ++++++------ include/spdlog/details/thread_pool.h | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/spdlog/details/circular_q.h b/include/spdlog/details/circular_q.h index b78af247..b01325bb 100644 --- a/include/spdlog/details/circular_q.h +++ b/include/spdlog/details/circular_q.h @@ -56,7 +56,7 @@ public: size_t overrun_counter() const { - return overrun_counter_; + return overrun_counter_; } private: diff --git a/include/spdlog/details/mpmc_blocking_q.h b/include/spdlog/details/mpmc_blocking_q.h index cf34d225..ca789fc6 100644 --- a/include/spdlog/details/mpmc_blocking_q.h +++ b/include/spdlog/details/mpmc_blocking_q.h @@ -30,12 +30,6 @@ public: { } - size_t overrun_counter() const - { - std::unique_lock lock(queue_mutex_); - return q_.overrun_counter(); - } - #ifndef __MINGW32__ // try to enqueue and block if no room left void enqueue(T &&item) @@ -111,6 +105,12 @@ public: #endif + size_t overrun_counter() + { + std::unique_lock lock(queue_mutex_); + return q_.overrun_counter(); + } + private: std::mutex queue_mutex_; std::condition_variable push_cv_; diff --git a/include/spdlog/details/thread_pool.h b/include/spdlog/details/thread_pool.h index aab089f4..282d67e8 100644 --- a/include/spdlog/details/thread_pool.h +++ b/include/spdlog/details/thread_pool.h @@ -157,9 +157,9 @@ public: post_async_msg_(async_msg(std::move(worker_ptr), async_msg_type::flush), overflow_policy); } - size_t overrun_counter() const + size_t overrun_counter() { - return q_.overrun_counter(); + return q_.overrun_counter(); } private: From 057bf1b92d018040393dda1e1ec1318fbd82000e Mon Sep 17 00:00:00 2001 From: gabime Date: Tue, 14 Aug 2018 17:57:55 +0300 Subject: [PATCH 39/82] Added some mpmc_q tests --- tests/CMakeLists.txt | 2 +- tests/test_mpmc_q.cpp | 105 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 tests/test_mpmc_q.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 18af9770..90a2ab9e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -14,7 +14,7 @@ set(SPDLOG_UTESTS_SOURCES test_macros.cpp utils.cpp utils.h - main.cpp) + main.cpp test_mpmc_q.cpp) add_executable(${PROJECT_NAME} ${SPDLOG_UTESTS_SOURCES}) target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads) diff --git a/tests/test_mpmc_q.cpp b/tests/test_mpmc_q.cpp new file mode 100644 index 00000000..37f0be44 --- /dev/null +++ b/tests/test_mpmc_q.cpp @@ -0,0 +1,105 @@ +#include "includes.h" + +using namespace std::chrono; +using std::chrono::system_clock; +using std::chrono::milliseconds; + +system_clock::time_point now_millis() +{ + return time_point_cast(system_clock::now()); +} +TEST_CASE("dequeue-empty-nowait", "[mpmc_blocking_q]") +{ + size_t q_size = 100; + milliseconds tolerance_wait(10); + spdlog::details::mpmc_blocking_queue q(q_size); + int popped_item; + + auto millis_0 = now_millis(); + auto rv = q.dequeue_for(popped_item, milliseconds::zero()); + auto millis_1 = now_millis(); + + REQUIRE(rv == false); + REQUIRE((millis_1-millis_0) <= tolerance_wait); + +} + +TEST_CASE("dequeue-empty-wait", "[mpmc_blocking_q]") +{ + + size_t q_size = 100; + milliseconds wait_ms(250); + milliseconds tolerance_wait(10); + + spdlog::details::mpmc_blocking_queue q(q_size); + int popped_item; + auto millis_0 = now_millis(); + auto rv = q.dequeue_for(popped_item, wait_ms); + auto millis_1 = now_millis(); + auto delta_ms = millis_1 - millis_0; + + REQUIRE(rv == false); + REQUIRE(delta_ms >= wait_ms); + REQUIRE(delta_ms <= wait_ms + tolerance_wait); +} + + +TEST_CASE("enqueue_nowait", "[mpmc_blocking_q]") +{ + + size_t q_size = 1; + spdlog::details::mpmc_blocking_queue q(q_size); + milliseconds tolerance_wait(10); + + q.enqueue(1); + REQUIRE(q.overrun_counter() == 0); + + auto millis_0 = now_millis(); + q.enqueue_nowait(2); + auto millis_1 = now_millis(); + REQUIRE((millis_1-millis_0) <= tolerance_wait); + REQUIRE(q.overrun_counter() == 1); +} + +TEST_CASE("bad_queue", "[mpmc_blocking_q]") +{ + size_t q_size = 0; + spdlog::details::mpmc_blocking_queue q(q_size); + q.enqueue_nowait(1); + REQUIRE(q.overrun_counter() == 1); + int i; + REQUIRE(q.dequeue_for(i, milliseconds(0)) == false); +} + +TEST_CASE("empty_queue", "[mpmc_blocking_q]") +{ + size_t q_size = 10; + spdlog::details::mpmc_blocking_queue q(q_size); + int i; + REQUIRE(q.dequeue_for(i, milliseconds(10)) == false); +} + +TEST_CASE("full_queue", "[mpmc_blocking_q]") +{ + size_t q_size = 100; + spdlog::details::mpmc_blocking_queue q(q_size); + for(int i = 0; i < static_cast(q_size); i++) + { + q.enqueue(std::move(i)); + } + + q.enqueue_nowait(123456); + REQUIRE(q.overrun_counter() == 1); + + for(int i = 1; i < static_cast(q_size); i++) + { + int item; + q.dequeue_for(item, milliseconds(0)); + REQUIRE(item == i); + } + + // last item pushed has overridden the oldest. + int item; + q.dequeue_for(item, milliseconds(0)); + REQUIRE(item == 123456); +} \ No newline at end of file From 4a871b97921c868b9dff6fe3bf15090689b666cf Mon Sep 17 00:00:00 2001 From: gabime Date: Tue, 14 Aug 2018 17:59:14 +0300 Subject: [PATCH 40/82] Added some mpmc_q tests --- tests/test_mpmc_q.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_mpmc_q.cpp b/tests/test_mpmc_q.cpp index 37f0be44..105445e7 100644 --- a/tests/test_mpmc_q.cpp +++ b/tests/test_mpmc_q.cpp @@ -93,13 +93,13 @@ TEST_CASE("full_queue", "[mpmc_blocking_q]") for(int i = 1; i < static_cast(q_size); i++) { - int item; + int item=-1; q.dequeue_for(item, milliseconds(0)); REQUIRE(item == i); } - + // last item pushed has overridden the oldest. - int item; + int item=-1; q.dequeue_for(item, milliseconds(0)); REQUIRE(item == 123456); } \ No newline at end of file From fb37585bc189b6e5af2a63a1e7c4b6b106a17720 Mon Sep 17 00:00:00 2001 From: Daniel Chabrowski Date: Tue, 14 Aug 2018 21:33:47 +0200 Subject: [PATCH 41/82] Little cmake and tests refactor Change from spdlog_ex to const spdlog_ex& got rid of the GCC8 warning. --- CMakeLists.txt | 10 ++++------ bench/CMakeLists.txt | 7 ------- example/CMakeLists.txt | 3 ++- example/multisink.cpp | 3 +-- tests/CMakeLists.txt | 13 +++++++++---- tests/errors.cpp | 7 +++---- tests/registry.cpp | 4 ++-- 7 files changed, 21 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b9319d17..0cdb421d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,13 +12,11 @@ include(GNUInstallDirs) #--------------------------------------------------------------------------------------- # 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) endif() -message("Build type: " ${CMAKE_BUILD_TYPE}) - - +message(STATUS "Build type: " ${CMAKE_BUILD_TYPE}) #--------------------------------------------------------------------------------------- # compiler config @@ -28,10 +26,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") - set(CMAKE_CXX_FLAGS "-Wall -Wextra ${CMAKE_CXX_FLAGS}") + add_compile_options("-Wall") + add_compile_options("-Wextra") endif() - #--------------------------------------------------------------------------------------- # address sanitizers check #--------------------------------------------------------------------------------------- diff --git a/bench/CMakeLists.txt b/bench/CMakeLists.txt index 946b762a..5e492c0b 100644 --- a/bench/CMakeLists.txt +++ b/bench/CMakeLists.txt @@ -24,10 +24,6 @@ cmake_minimum_required(VERSION 3.1) project(SpdlogBench CXX) -if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") -endif() - if(NOT TARGET spdlog) # Stand-alone build find_package(spdlog CONFIG REQUIRED) @@ -44,7 +40,4 @@ target_link_libraries(async_bench spdlog::spdlog Threads::Threads) add_executable(latency latency.cpp) target_link_libraries(latency spdlog::spdlog Threads::Threads) - - file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs") - diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 69eb374e..695053cd 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -37,6 +37,7 @@ target_link_libraries(example spdlog::spdlog Threads::Threads) add_executable(multisink multisink.cpp) target_link_libraries(multisink spdlog::spdlog Threads::Threads) -enable_testing() file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs") + +enable_testing() add_test(NAME example COMMAND example) diff --git a/example/multisink.cpp b/example/multisink.cpp index fefa3b39..7dc267d2 100644 --- a/example/multisink.cpp +++ b/example/multisink.cpp @@ -4,7 +4,6 @@ #include #include -namespace spd = spdlog; int main(int, char *[]) { bool enable_debug = true; @@ -39,7 +38,7 @@ int main(int, char *[]) spdlog::drop_all(); } // Exceptions will only be thrown upon failed logger or sink construction (not during logging) - catch (const spd::spdlog_ex &ex) + catch (const spdlog::spdlog_ex &ex) { std::cout << "Log init failed: " << ex.what() << std::endl; return 1; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 90a2ab9e..2fb0b4b2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,5 +1,5 @@ project(spdlog-utests CXX) -enable_testing() + find_package(Threads REQUIRED) set(SPDLOG_UTESTS_SOURCES @@ -7,18 +7,23 @@ set(SPDLOG_UTESTS_SOURCES file_helper.cpp file_log.cpp test_misc.cpp - test_pattern_formatter.cpp + test_pattern_formatter.cpp test_async.cpp includes.h registry.cpp test_macros.cpp utils.cpp utils.h - main.cpp test_mpmc_q.cpp) + main.cpp + test_mpmc_q.cpp + test_sink.h +) add_executable(${PROJECT_NAME} ${SPDLOG_UTESTS_SOURCES}) target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads) target_link_libraries(${PROJECT_NAME} PRIVATE spdlog::spdlog) -add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME}) file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs") + +enable_testing() +add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME}) diff --git a/tests/errors.cpp b/tests/errors.cpp index 32209b43..40f3723f 100644 --- a/tests/errors.cpp +++ b/tests/errors.cpp @@ -9,15 +9,15 @@ class failing_sink : public spdlog::sinks::base_sink { public: failing_sink() = default; - ~failing_sink() = default; + ~failing_sink() final = default; protected: - void sink_it_(const spdlog::details::log_msg &) override + void sink_it_(const spdlog::details::log_msg &) final { throw std::runtime_error("some error happened during log"); } - void flush_() override + void flush_() final { throw std::runtime_error("some error happened during flush"); } @@ -25,7 +25,6 @@ protected: TEST_CASE("default_error_handler", "[errors]]") { - prepare_logdir(); std::string filename = "logs/simple_log.txt"; diff --git a/tests/registry.cpp b/tests/registry.cpp index 0c581bc0..e682a939 100644 --- a/tests/registry.cpp +++ b/tests/registry.cpp @@ -9,7 +9,7 @@ TEST_CASE("register_drop", "[registry]") spdlog::create(tested_logger_name); REQUIRE(spdlog::get(tested_logger_name) != nullptr); // Throw if registring existing name - REQUIRE_THROWS_AS(spdlog::create(tested_logger_name), spdlog::spdlog_ex); + REQUIRE_THROWS_AS(spdlog::create(tested_logger_name), const spdlog::spdlog_ex&); } TEST_CASE("explicit register" @@ -20,7 +20,7 @@ TEST_CASE("explicit register" spdlog::register_logger(logger); REQUIRE(spdlog::get(tested_logger_name) != nullptr); // Throw if registring existing name - REQUIRE_THROWS_AS(spdlog::create(tested_logger_name), spdlog::spdlog_ex); + REQUIRE_THROWS_AS(spdlog::create(tested_logger_name), const spdlog::spdlog_ex&); } TEST_CASE("apply_all" From b962fbb15c9f1fb2f5410ff0cf3a4065088c717e Mon Sep 17 00:00:00 2001 From: gabime Date: Wed, 15 Aug 2018 19:01:44 +0300 Subject: [PATCH 42/82] Fixed issue #797 --- include/spdlog/common.h | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/include/spdlog/common.h b/include/spdlog/common.h index ddb0d28c..1542fa92 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -100,6 +100,7 @@ inline const char *to_short_c_str(spdlog::level::level_enum l) { return short_level_names[l]; } + inline spdlog::level::level_enum from_str(const std::string &name) { static std::unordered_map name_to_level = // map string->level @@ -131,35 +132,28 @@ enum class pattern_time_type // // Log exception // -class spdlog_ex : public std::runtime_error +class spdlog_ex : public std::exception { public: explicit spdlog_ex(const std::string &msg) - : runtime_error(msg) + : msg_(msg) { } + spdlog_ex(const std::string &msg, int last_errno) - : runtime_error(msg) - , last_errno_(last_errno) { + fmt::memory_buffer outbuf; + fmt::format_system_error(outbuf, last_errno, msg); + msg_ = fmt::to_string(outbuf); } + const char *what() const SPDLOG_NOEXCEPT override { - if (last_errno_) - { - fmt::memory_buffer buf; - std::string msg(runtime_error::what()); - fmt::format_system_error(buf, last_errno_, msg); - return fmt::to_string(buf).c_str(); - } - else - { - return runtime_error::what(); - } + return msg_.c_str(); } private: - int last_errno_{0}; + std::string msg_; }; // From 3d58f8d47172e310b3782fb89695783922ea8988 Mon Sep 17 00:00:00 2001 From: gabime Date: Wed, 15 Aug 2018 19:01:54 +0300 Subject: [PATCH 43/82] code formatting --- tests/test_mpmc_q.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/tests/test_mpmc_q.cpp b/tests/test_mpmc_q.cpp index 105445e7..21b2e8a2 100644 --- a/tests/test_mpmc_q.cpp +++ b/tests/test_mpmc_q.cpp @@ -1,8 +1,8 @@ #include "includes.h" using namespace std::chrono; -using std::chrono::system_clock; using std::chrono::milliseconds; +using std::chrono::system_clock; system_clock::time_point now_millis() { @@ -20,8 +20,7 @@ TEST_CASE("dequeue-empty-nowait", "[mpmc_blocking_q]") auto millis_1 = now_millis(); REQUIRE(rv == false); - REQUIRE((millis_1-millis_0) <= tolerance_wait); - + REQUIRE((millis_1 - millis_0) <= tolerance_wait); } TEST_CASE("dequeue-empty-wait", "[mpmc_blocking_q]") @@ -43,7 +42,6 @@ TEST_CASE("dequeue-empty-wait", "[mpmc_blocking_q]") REQUIRE(delta_ms <= wait_ms + tolerance_wait); } - TEST_CASE("enqueue_nowait", "[mpmc_blocking_q]") { @@ -57,7 +55,7 @@ TEST_CASE("enqueue_nowait", "[mpmc_blocking_q]") auto millis_0 = now_millis(); q.enqueue_nowait(2); auto millis_1 = now_millis(); - REQUIRE((millis_1-millis_0) <= tolerance_wait); + REQUIRE((millis_1 - millis_0) <= tolerance_wait); REQUIRE(q.overrun_counter() == 1); } @@ -83,7 +81,7 @@ TEST_CASE("full_queue", "[mpmc_blocking_q]") { size_t q_size = 100; spdlog::details::mpmc_blocking_queue q(q_size); - for(int i = 0; i < static_cast(q_size); i++) + for (int i = 0; i < static_cast(q_size); i++) { q.enqueue(std::move(i)); } @@ -91,15 +89,15 @@ TEST_CASE("full_queue", "[mpmc_blocking_q]") q.enqueue_nowait(123456); REQUIRE(q.overrun_counter() == 1); - for(int i = 1; i < static_cast(q_size); i++) + for (int i = 1; i < static_cast(q_size); i++) { - int item=-1; + int item = -1; q.dequeue_for(item, milliseconds(0)); REQUIRE(item == i); } // last item pushed has overridden the oldest. - int item=-1; + int item = -1; q.dequeue_for(item, milliseconds(0)); REQUIRE(item == 123456); } \ No newline at end of file From ebea09c8b45b73fc253effffbd18205953aa7db3 Mon Sep 17 00:00:00 2001 From: gabime Date: Wed, 15 Aug 2018 19:09:37 +0300 Subject: [PATCH 44/82] Added pedantic flag to compiler in cmake --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0cdb421d..b4e3a63f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ set(CMAKE_CXX_EXTENSIONS OFF) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") add_compile_options("-Wall") add_compile_options("-Wextra") + add_compile_options("-pedantic") endif() #--------------------------------------------------------------------------------------- From b6b9d835c588c35227410a9830e7a4586f90777a Mon Sep 17 00:00:00 2001 From: gabime Date: Wed, 15 Aug 2018 19:34:10 +0300 Subject: [PATCH 45/82] Version 1.1.0 --- CMakeLists.txt | 2 +- include/spdlog/version.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b4e3a63f..fee56552 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ # cmake_minimum_required(VERSION 3.1) -project(spdlog VERSION 1.0.1 LANGUAGES CXX) +project(spdlog VERSION 1.1.0 LANGUAGES CXX) include(CTest) include(CMakeDependentOption) include(GNUInstallDirs) diff --git a/include/spdlog/version.h b/include/spdlog/version.h index 87d0b3e8..f14078ec 100644 --- a/include/spdlog/version.h +++ b/include/spdlog/version.h @@ -6,7 +6,7 @@ #pragma once #define SPDLOG_VER_MAJOR 1 -#define SPDLOG_VER_MINOR 0 -#define SPDLOG_VER_PATCH 1 +#define SPDLOG_VER_MINOR 1 +#define SPDLOG_VER_PATCH 0 #define SPDLOG_VERSION (SPDLOG_VER_MAJOR * 10000 + SPDLOG_VER_MINOR * 100 + SPDLOG_VER_PATCH) From b51c8cfd0fead4c8eefee27ea7fc0719d7370edd Mon Sep 17 00:00:00 2001 From: Daniel Chabrowski Date: Thu, 16 Aug 2018 17:53:55 +0200 Subject: [PATCH 46/82] Fix registry test --- tests/registry.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/registry.cpp b/tests/registry.cpp index e682a939..29bd1fc0 100644 --- a/tests/registry.cpp +++ b/tests/registry.cpp @@ -62,7 +62,7 @@ TEST_CASE("drop_all" spdlog::create(tested_logger_name2); spdlog::drop_all(); REQUIRE_FALSE(spdlog::get(tested_logger_name)); - REQUIRE_FALSE(spdlog::get(tested_logger_name)); + REQUIRE_FALSE(spdlog::get(tested_logger_name2)); } TEST_CASE("drop non existing" From a58d7594cb9d2a8948feb94426617002f0e16fd2 Mon Sep 17 00:00:00 2001 From: gabime Date: Fri, 17 Aug 2018 00:32:13 +0300 Subject: [PATCH 47/82] Fixed issue #798 and added -Wconversion compiler flag to build --- CMakeLists.txt | 2 ++ bench/bench.cpp | 6 +++--- bench/latency.cpp | 6 +++--- example/Makefile | 2 +- include/spdlog/details/fmt_helper.h | 12 ++++++------ include/spdlog/sinks/ostream_sink.h | 2 +- tests/Makefile | 2 +- tests/registry.cpp | 4 ++-- 8 files changed, 19 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fee56552..3eee0dae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,9 @@ set(CMAKE_CXX_EXTENSIONS OFF) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") add_compile_options("-Wall") add_compile_options("-Wextra") + add_compile_options("-Wconversion") add_compile_options("-pedantic") + endif() #--------------------------------------------------------------------------------------- diff --git a/bench/bench.cpp b/bench/bench.cpp index f5a8060b..db14e1af 100644 --- a/bench/bench.cpp +++ b/bench/bench.cpp @@ -35,8 +35,8 @@ int main(int argc, char *argv[]) int howmany = 1000000; int queue_size = howmany + 2; int threads = 10; - int file_size = 30 * 1024 * 1024; - int rotating_files = 5; + size_t file_size = 30 * 1024 * 1024; + size_t rotating_files = 5; try { @@ -89,7 +89,7 @@ int main(int argc, char *argv[]) for (int i = 0; i < 3; ++i) { - spdlog::init_thread_pool(queue_size, 1); + spdlog::init_thread_pool(static_cast(queue_size), 1); auto as = spdlog::basic_logger_mt("async", "logs/basic_async.log", true); bench_mt(howmany, as, threads); spdlog::drop("async"); diff --git a/bench/latency.cpp b/bench/latency.cpp index 374eafb0..dcc6965c 100644 --- a/bench/latency.cpp +++ b/bench/latency.cpp @@ -35,8 +35,8 @@ int main(int, char *[]) int howmany = 1000000; int queue_size = howmany + 2; int threads = 10; - int file_size = 30 * 1024 * 1024; - int rotating_files = 5; + size_t file_size = 30 * 1024 * 1024; + size_t rotating_files = 5; try { @@ -82,7 +82,7 @@ int main(int, char *[]) for (int i = 0; i < 3; ++i) { - spdlog::init_thread_pool(queue_size, 1); + spdlog::init_thread_pool(static_cast(queue_size), 1); auto as = spdlog::basic_logger_mt("async", "logs/basic_async.log", true); bench_mt(howmany, as, threads); spdlog::drop("async"); diff --git a/example/Makefile b/example/Makefile index 01bdf507..bd6b2922 100644 --- a/example/Makefile +++ b/example/Makefile @@ -1,5 +1,5 @@ CXX ?= g++ -CXX_FLAGS = -Wall -Wextra -pedantic -std=c++11 -pthread -I../include -fmax-errors=1 +CXX_FLAGS = -Wall -Wextra -pedantic -std=c++11 -pthread -I../include -fmax-errors=1 -Wconversion CXX_RELEASE_FLAGS = -O3 -march=native CXX_DEBUG_FLAGS= -g diff --git a/include/spdlog/details/fmt_helper.h b/include/spdlog/details/fmt_helper.h index eabf93b5..a94c7c5e 100644 --- a/include/spdlog/details/fmt_helper.h +++ b/include/spdlog/details/fmt_helper.h @@ -54,14 +54,14 @@ inline void pad2(int n, fmt::basic_memory_buffer &dest) } if (n > 9) // 10-99 { - dest.push_back('0' + static_cast(n / 10)); - dest.push_back('0' + static_cast(n % 10)); + dest.push_back(static_cast('0' + n / 10)); + dest.push_back(static_cast('0' + n % 10)); return; } if (n >= 0) // 0-9 { dest.push_back('0'); - dest.push_back('0' + static_cast(n)); + dest.push_back(static_cast('0' + n)); return; } // negatives (unlikely, but just in case, let fmt deal with it) @@ -86,15 +86,15 @@ inline void pad3(int n, fmt::basic_memory_buffer &dest) if (n > 9) // 10-99 { dest.push_back('0'); - dest.push_back('0' + static_cast(n / 10)); - dest.push_back('0' + static_cast(n % 10)); + dest.push_back(static_cast('0' + n / 10)); + dest.push_back(static_cast('0' + n % 10)); return; } if (n >= 0) { dest.push_back('0'); dest.push_back('0'); - dest.push_back('0' + static_cast(n)); + dest.push_back(static_cast('0' + n)); return; } // negatives (unlikely, but just in case let fmt deal with it) diff --git a/include/spdlog/sinks/ostream_sink.h b/include/spdlog/sinks/ostream_sink.h index 5f31993c..00c15959 100644 --- a/include/spdlog/sinks/ostream_sink.h +++ b/include/spdlog/sinks/ostream_sink.h @@ -30,7 +30,7 @@ protected: { fmt::memory_buffer formatted; sink::formatter_->format(msg, formatted); - ostream_.write(formatted.data(), formatted.size()); + ostream_.write(formatted.data(), static_cast(formatted.size())); if (force_flush_) ostream_.flush(); } diff --git a/tests/Makefile b/tests/Makefile index 00c7c589..bec3026d 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,5 +1,5 @@ CXX ?= g++ -CXXFLAGS = -Wall -pedantic -std=c++11 -pthread -O3 -I../include -fmax-errors=1 +CXXFLAGS = -Wall -pedantic -std=c++11 -pthread -Wconversion -O3 -I../include -fmax-errors=1 LDPFALGS = -pthread CPP_FILES := $(wildcard *.cpp) diff --git a/tests/registry.cpp b/tests/registry.cpp index 29bd1fc0..1b841a4c 100644 --- a/tests/registry.cpp +++ b/tests/registry.cpp @@ -9,7 +9,7 @@ TEST_CASE("register_drop", "[registry]") spdlog::create(tested_logger_name); REQUIRE(spdlog::get(tested_logger_name) != nullptr); // Throw if registring existing name - REQUIRE_THROWS_AS(spdlog::create(tested_logger_name), const spdlog::spdlog_ex&); + REQUIRE_THROWS_AS(spdlog::create(tested_logger_name), const spdlog::spdlog_ex &); } TEST_CASE("explicit register" @@ -20,7 +20,7 @@ TEST_CASE("explicit register" spdlog::register_logger(logger); REQUIRE(spdlog::get(tested_logger_name) != nullptr); // Throw if registring existing name - REQUIRE_THROWS_AS(spdlog::create(tested_logger_name), const spdlog::spdlog_ex&); + REQUIRE_THROWS_AS(spdlog::create(tested_logger_name), const spdlog::spdlog_ex &); } TEST_CASE("apply_all" From 28435dc73665a3f060a65f512c1273ed67f68ab9 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Fri, 17 Aug 2018 14:06:48 +0300 Subject: [PATCH 48/82] Normalized spdlog includes in file_helper --- include/spdlog/details/file_helper.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/spdlog/details/file_helper.h b/include/spdlog/details/file_helper.h index 65b3560f..fe817921 100644 --- a/include/spdlog/details/file_helper.h +++ b/include/spdlog/details/file_helper.h @@ -10,8 +10,8 @@ // the tries(10 ms) // Throw spdlog_ex exception on errors -#include "../details/log_msg.h" -#include "../details/os.h" +#include "spdlog/details/log_msg.h" +#include "spdlog/details/os.h" #include #include From 176cab4feefd742c38e98547c1261c98312ef445 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Fri, 17 Aug 2018 14:07:49 +0300 Subject: [PATCH 49/82] Update file_helper.h --- include/spdlog/details/file_helper.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/spdlog/details/file_helper.h b/include/spdlog/details/file_helper.h index fe817921..8626078c 100644 --- a/include/spdlog/details/file_helper.h +++ b/include/spdlog/details/file_helper.h @@ -146,7 +146,7 @@ public: } private: - FILE *fd_{nullptr}; + std::FILE *fd_{nullptr}; filename_t _filename; }; } // namespace details From acd7a88bf2fcafa128f29b205a586ea39e7e0b0c Mon Sep 17 00:00:00 2001 From: gabime Date: Fri, 17 Aug 2018 15:58:53 +0300 Subject: [PATCH 50/82] Try adding osx to travis --- .travis.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.travis.yml b/.travis.yml index b0dbcba7..c4beaa5e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,6 +39,7 @@ addons: &clang6 - ubuntu-toolchain-r-test - llvm-toolchain-trusty-6.0 + matrix: include: # Test gcc-4.8: C++11, Build=Debug/Release @@ -81,10 +82,18 @@ matrix: os: linux addons: *clang6 + # osx + - env: CLANG_VERSION=6.0 BUILD_TYPE=Release CPP=11 ASAN=Off TSAN=Off + os: osx + + + + before_script: - if [ -n "$GCC_VERSION" ]; then export CXX="g++-${GCC_VERSION}" CC="gcc-${GCC_VERSION}"; fi - if [ -n "$CLANG_VERSION" ]; then export CXX="clang++-${CLANG_VERSION}" CC="clang-${CLANG_VERSION}"; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; export CXX="clang++" CC="clang"; fi - which $CXX - which $CC - which valgrind From 3b3af1ab1e5bf9b0f63047fcfe3c9ecf7d630f58 Mon Sep 17 00:00:00 2001 From: gabime Date: Fri, 17 Aug 2018 16:00:14 +0300 Subject: [PATCH 51/82] Try adding osx to travis --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index c4beaa5e..6e83e18a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -83,8 +83,8 @@ matrix: addons: *clang6 # osx - - env: CLANG_VERSION=6.0 BUILD_TYPE=Release CPP=11 ASAN=Off TSAN=Off - os: osx + - env: CLANG_VERSION=6.0 BUILD_TYPE=Release CPP=11 ASAN=Off TSAN=Off + os: osx From af5962450ef0c9b6a2e0dc671cab18fe894fe798 Mon Sep 17 00:00:00 2001 From: gabime Date: Fri, 17 Aug 2018 16:15:02 +0300 Subject: [PATCH 52/82] Try adding osx to travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6e83e18a..bb455a73 100644 --- a/.travis.yml +++ b/.travis.yml @@ -93,7 +93,7 @@ matrix: before_script: - if [ -n "$GCC_VERSION" ]; then export CXX="g++-${GCC_VERSION}" CC="gcc-${GCC_VERSION}"; fi - if [ -n "$CLANG_VERSION" ]; then export CXX="clang++-${CLANG_VERSION}" CC="clang-${CLANG_VERSION}"; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; export CXX="clang++" CC="clang"; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export CXX="clang++" CC="clang"; fi - which $CXX - which $CC - which valgrind From a281d21fbfdb1d8933d0d93e67b562313cd4ac33 Mon Sep 17 00:00:00 2001 From: gabime Date: Fri, 17 Aug 2018 16:26:52 +0300 Subject: [PATCH 53/82] Removed valgrind from travis --- .travis.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index bb455a73..c4dac96a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,6 @@ addons: &gcc48 apt: packages: - g++-4.8 - - valgrind sources: - ubuntu-toolchain-r-test @@ -17,7 +16,6 @@ addons: &gcc7 apt: packages: - g++-7 - - valgrind sources: - ubuntu-toolchain-r-test @@ -25,7 +23,6 @@ addons: &clang35 apt: packages: - clang-3.5 - - valgrind sources: - ubuntu-toolchain-r-test - llvm-toolchain-precise-3.5 @@ -34,7 +31,6 @@ addons: &clang6 apt: packages: - clang-6.0 - - valgrind sources: - ubuntu-toolchain-r-test - llvm-toolchain-trusty-6.0 @@ -96,10 +92,8 @@ before_script: - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export CXX="clang++" CC="clang"; fi - which $CXX - which $CC - - which valgrind - $CXX --version - cmake --version - - valgrind --version script: - cd ${TRAVIS_BUILD_DIR} From 9ad9cfb898c1f965b5a94990477f497e03f92925 Mon Sep 17 00:00:00 2001 From: gabime Date: Fri, 17 Aug 2018 17:17:16 +0300 Subject: [PATCH 54/82] Fixed mpmc_q test for osx in travis --- .travis.yml | 2 -- tests/includes.h | 1 + tests/test_mpmc_q.cpp | 35 ++++++++++++++++++++--------------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index c4dac96a..12019901 100644 --- a/.travis.yml +++ b/.travis.yml @@ -84,8 +84,6 @@ matrix: - - before_script: - if [ -n "$GCC_VERSION" ]; then export CXX="g++-${GCC_VERSION}" CC="gcc-${GCC_VERSION}"; fi - if [ -n "$CLANG_VERSION" ]; then export CXX="clang++-${CLANG_VERSION}" CC="clang-${CLANG_VERSION}"; fi diff --git a/tests/includes.h b/tests/includes.h index c9056a02..4d35d6b8 100644 --- a/tests/includes.h +++ b/tests/includes.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #define SPDLOG_TRACE_ON diff --git a/tests/test_mpmc_q.cpp b/tests/test_mpmc_q.cpp index 21b2e8a2..19c6cdf3 100644 --- a/tests/test_mpmc_q.cpp +++ b/tests/test_mpmc_q.cpp @@ -2,25 +2,27 @@ using namespace std::chrono; using std::chrono::milliseconds; -using std::chrono::system_clock; +using test_clock = std::chrono::high_resolution_clock ; -system_clock::time_point now_millis() + +static milliseconds millis_from(const test_clock::time_point &tp0) { - return time_point_cast(system_clock::now()); + return std::chrono::duration_cast(test_clock::now()-tp0); } TEST_CASE("dequeue-empty-nowait", "[mpmc_blocking_q]") { size_t q_size = 100; - milliseconds tolerance_wait(10); + milliseconds tolerance_wait(30); spdlog::details::mpmc_blocking_queue q(q_size); int popped_item; - auto millis_0 = now_millis(); + auto start = test_clock::now(); auto rv = q.dequeue_for(popped_item, milliseconds::zero()); - auto millis_1 = now_millis(); + auto delta_ms = millis_from(start); REQUIRE(rv == false); - REQUIRE((millis_1 - millis_0) <= tolerance_wait); + INFO("Delta " << delta_ms.count() << " millis"); + REQUIRE(delta_ms <= tolerance_wait); } TEST_CASE("dequeue-empty-wait", "[mpmc_blocking_q]") @@ -28,16 +30,17 @@ TEST_CASE("dequeue-empty-wait", "[mpmc_blocking_q]") size_t q_size = 100; milliseconds wait_ms(250); - milliseconds tolerance_wait(10); + milliseconds tolerance_wait(30); spdlog::details::mpmc_blocking_queue q(q_size); int popped_item; - auto millis_0 = now_millis(); + auto start = test_clock::now(); auto rv = q.dequeue_for(popped_item, wait_ms); - auto millis_1 = now_millis(); - auto delta_ms = millis_1 - millis_0; + auto delta_ms = millis_from(start); REQUIRE(rv == false); + + INFO("Delta " << delta_ms.count() << " millis"); REQUIRE(delta_ms >= wait_ms); REQUIRE(delta_ms <= wait_ms + tolerance_wait); } @@ -47,15 +50,17 @@ TEST_CASE("enqueue_nowait", "[mpmc_blocking_q]") size_t q_size = 1; spdlog::details::mpmc_blocking_queue q(q_size); - milliseconds tolerance_wait(10); + milliseconds tolerance_wait(30); q.enqueue(1); REQUIRE(q.overrun_counter() == 0); - auto millis_0 = now_millis(); + auto start = test_clock::now(); q.enqueue_nowait(2); - auto millis_1 = now_millis(); - REQUIRE((millis_1 - millis_0) <= tolerance_wait); + auto delta_ms = millis_from(start); + + INFO("Delta " << delta_ms.count() << " millis"); + REQUIRE(delta_ms <= tolerance_wait); REQUIRE(q.overrun_counter() == 1); } From 8418131ae34452b5e0db531d183e50c230d54e88 Mon Sep 17 00:00:00 2001 From: gabime Date: Fri, 17 Aug 2018 17:30:33 +0300 Subject: [PATCH 55/82] Fixed mpmc_q test for osx in travis --- .travis.yml | 10 +++++++++- tests/test_mpmc_q.cpp | 6 +++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 12019901..d0cb80e8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -79,9 +79,17 @@ matrix: addons: *clang6 # osx - - env: CLANG_VERSION=6.0 BUILD_TYPE=Release CPP=11 ASAN=Off TSAN=Off + - env: BUILD_TYPE=Release CPP=11 ASAN=Off TSAN=Off os: osx + - env: BUILD_TYPE=Debug CPP=11 ASAN=On TSAN=Off + os: osx + + - env: BUILD_TYPE=Debug CPP=11 ASAN=Off TSAN=On + os: osx + + + before_script: diff --git a/tests/test_mpmc_q.cpp b/tests/test_mpmc_q.cpp index 19c6cdf3..ddb31961 100644 --- a/tests/test_mpmc_q.cpp +++ b/tests/test_mpmc_q.cpp @@ -12,7 +12,7 @@ static milliseconds millis_from(const test_clock::time_point &tp0) TEST_CASE("dequeue-empty-nowait", "[mpmc_blocking_q]") { size_t q_size = 100; - milliseconds tolerance_wait(30); + milliseconds tolerance_wait(10); spdlog::details::mpmc_blocking_queue q(q_size); int popped_item; @@ -30,7 +30,7 @@ TEST_CASE("dequeue-empty-wait", "[mpmc_blocking_q]") size_t q_size = 100; milliseconds wait_ms(250); - milliseconds tolerance_wait(30); + milliseconds tolerance_wait(100); spdlog::details::mpmc_blocking_queue q(q_size); int popped_item; @@ -50,7 +50,7 @@ TEST_CASE("enqueue_nowait", "[mpmc_blocking_q]") size_t q_size = 1; spdlog::details::mpmc_blocking_queue q(q_size); - milliseconds tolerance_wait(30); + milliseconds tolerance_wait(10); q.enqueue(1); REQUIRE(q.overrun_counter() == 0); From 45d3c8341cc478823da87d0adb1d22edf973f17f Mon Sep 17 00:00:00 2001 From: gabime Date: Fri, 17 Aug 2018 17:45:48 +0300 Subject: [PATCH 56/82] Fixed mpmc_q test for osx in travis --- .travis.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index d0cb80e8..49ea5476 100644 --- a/.travis.yml +++ b/.travis.yml @@ -81,14 +81,7 @@ matrix: # osx - env: BUILD_TYPE=Release CPP=11 ASAN=Off TSAN=Off os: osx - - - env: BUILD_TYPE=Debug CPP=11 ASAN=On TSAN=Off - os: osx - - - env: BUILD_TYPE=Debug CPP=11 ASAN=Off TSAN=On - os: osx - - + From 0758b3906174815ff34c2f5b7a89ede2ffd627ec Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 18 Aug 2018 02:19:52 +0300 Subject: [PATCH 57/82] Stop compilation on first error --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3eee0dae..c0b8a373 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,7 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCH add_compile_options("-Wextra") add_compile_options("-Wconversion") add_compile_options("-pedantic") + add_compile_options("-Wfatal-errors") endif() From 3151081ff36b6f4fa0400146584679147403d982 Mon Sep 17 00:00:00 2001 From: yhchen Date: Sun, 19 Aug 2018 17:21:15 +0800 Subject: [PATCH 58/82] remove invalid files from project --- tests/tests.sln | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/tests.sln b/tests/tests.sln index 00d98a9f..e34e5636 100644 --- a/tests/tests.sln +++ b/tests/tests.sln @@ -56,7 +56,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sinks", "sinks", "{093AE34A ..\include\spdlog\sinks\ansicolor_sink.h = ..\include\spdlog\sinks\ansicolor_sink.h ..\include\spdlog\sinks\base_sink.h = ..\include\spdlog\sinks\base_sink.h ..\include\spdlog\sinks\dist_sink.h = ..\include\spdlog\sinks\dist_sink.h - ..\include\spdlog\sinks\file_sinks.h = ..\include\spdlog\sinks\file_sinks.h ..\include\spdlog\sinks\msvc_sink.h = ..\include\spdlog\sinks\msvc_sink.h ..\include\spdlog\sinks\null_sink.h = ..\include\spdlog\sinks\null_sink.h ..\include\spdlog\sinks\ostream_sink.h = ..\include\spdlog\sinks\ostream_sink.h @@ -65,7 +64,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sinks", "sinks", "{093AE34A ..\include\spdlog\sinks\stdout_sinks.h = ..\include\spdlog\sinks\stdout_sinks.h ..\include\spdlog\sinks\syslog_sink.h = ..\include\spdlog\sinks\syslog_sink.h ..\include\spdlog\sinks\wincolor_sink.h = ..\include\spdlog\sinks\wincolor_sink.h - ..\include\spdlog\sinks\windebug_sink.h = ..\include\spdlog\sinks\windebug_sink.h EndProjectSection EndProject Global From d3c1ad29a064d001da2435db56f159784ef54964 Mon Sep 17 00:00:00 2001 From: gabime Date: Mon, 20 Aug 2018 12:43:31 +0300 Subject: [PATCH 59/82] Optimize logging for const char* messages --- include/spdlog/details/fmt_helper.h | 8 ++------ include/spdlog/details/logger_impl.h | 7 +++++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/include/spdlog/details/fmt_helper.h b/include/spdlog/details/fmt_helper.h index a94c7c5e..76a00b4c 100644 --- a/include/spdlog/details/fmt_helper.h +++ b/include/spdlog/details/fmt_helper.h @@ -22,12 +22,8 @@ inline void append_str(const std::string &str, fmt::basic_memory_buffer inline void append_c_str(const char *c_str, fmt::basic_memory_buffer &dest) { - char ch; - while ((ch = *c_str) != '\0') - { - dest.push_back(ch); - ++c_str; - } + auto len = std::char_traits::length(c_str); + dest.append(c_str, c_str + len); } template diff --git a/include/spdlog/details/logger_impl.h b/include/spdlog/details/logger_impl.h index 0a7c5b6b..1451adc6 100644 --- a/include/spdlog/details/logger_impl.h +++ b/include/spdlog/details/logger_impl.h @@ -5,9 +5,12 @@ #pragma once +#include "spdlog/details/fmt_helper.h" + #include #include + // create logger with given name, sinks and the default pattern formatter // all other ctors will call this one template @@ -76,8 +79,8 @@ inline void spdlog::logger::log(level::level_enum lvl, const char *msg) } try { - details::log_msg log_msg(&name_, lvl); - fmt::format_to(log_msg.raw, "{}", msg); + details::log_msg log_msg(&name_, lvl); + details::fmt_helper::append_c_str(msg, log_msg.raw); sink_it_(log_msg); } SPDLOG_CATCH_AND_HANDLE From 2870afdeaef1ae5041f54e4583e7e10a5d4cbc85 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Tue, 21 Aug 2018 03:37:29 +0300 Subject: [PATCH 60/82] Update stdout_sinks.h --- include/spdlog/sinks/stdout_sinks.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/spdlog/sinks/stdout_sinks.h b/include/spdlog/sinks/stdout_sinks.h index e12739c1..6106cd08 100644 --- a/include/spdlog/sinks/stdout_sinks.h +++ b/include/spdlog/sinks/stdout_sinks.h @@ -12,7 +12,6 @@ #include #include #include -#include namespace spdlog { From 3edc7f1d182b1f7d77d50df4e60aafb6143a1bfc Mon Sep 17 00:00:00 2001 From: Daniel Chabrowski Date: Wed, 22 Aug 2018 21:46:46 +0200 Subject: [PATCH 61/82] Add missing include in console_globals.h --- include/spdlog/details/console_globals.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/spdlog/details/console_globals.h b/include/spdlog/details/console_globals.h index 4ac7f743..128003ea 100644 --- a/include/spdlog/details/console_globals.h +++ b/include/spdlog/details/console_globals.h @@ -8,6 +8,10 @@ #include #include +#ifdef _WIN32 +#include "spdlog/details/os.h" +#endif + namespace spdlog { namespace details { struct console_stdout From 299012605485077b1f92415d34ac11db92c5b8f7 Mon Sep 17 00:00:00 2001 From: Daniel Chabrowski Date: Wed, 22 Aug 2018 22:47:16 +0200 Subject: [PATCH 62/82] Change console_globals include to windows.h only --- include/spdlog/details/console_globals.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/include/spdlog/details/console_globals.h b/include/spdlog/details/console_globals.h index 128003ea..e2afb6bf 100644 --- a/include/spdlog/details/console_globals.h +++ b/include/spdlog/details/console_globals.h @@ -9,7 +9,16 @@ #include #ifdef _WIN32 -#include "spdlog/details/os.h" + +#ifndef NOMINMAX +#define NOMINMAX // prevent windows redefining min/max +#endif + +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif + +#include #endif namespace spdlog { From 39492436ec835b20389336ef26ae501e31a76eeb Mon Sep 17 00:00:00 2001 From: eruiz Date: Thu, 23 Aug 2018 12:20:26 -0300 Subject: [PATCH 63/82] WIN32: Don't deny access to file sinks from other processes --- include/spdlog/details/os.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/spdlog/details/os.h b/include/spdlog/details/os.h index d7f7430f..7ee42542 100644 --- a/include/spdlog/details/os.h +++ b/include/spdlog/details/os.h @@ -159,9 +159,9 @@ inline bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mod { #ifdef _WIN32 #ifdef SPDLOG_WCHAR_FILENAMES - *fp = _wfsopen((filename.c_str()), mode.c_str(), _SH_DENYWR); + *fp = _wfsopen((filename.c_str()), mode.c_str(), _SH_DENYNO); #else - *fp = _fsopen((filename.c_str()), mode.c_str(), _SH_DENYWR); + *fp = _fsopen((filename.c_str()), mode.c_str(), _SH_DENYNO); #endif #else // unix *fp = fopen((filename.c_str()), mode.c_str()); From f6049cd3330a059920ec12402923104310e3d934 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Fri, 24 Aug 2018 13:26:45 +0300 Subject: [PATCH 64/82] Update file_helper.h --- include/spdlog/details/file_helper.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/include/spdlog/details/file_helper.h b/include/spdlog/details/file_helper.h index 8626078c..bca59420 100644 --- a/include/spdlog/details/file_helper.h +++ b/include/spdlog/details/file_helper.h @@ -5,10 +5,9 @@ #pragma once -// Helper class for file sink -// When failing to open a file, retry several times(5) with small delay between -// the tries(10 ms) -// Throw spdlog_ex exception on errors +// Helper class for file sink. +// When failing to open a file, retry several times(5) with delay interval (10 ms). +// Throw spdlog_ex exception on errors. #include "spdlog/details/log_msg.h" #include "spdlog/details/os.h" From d0cfca082020d350388fb0b39708830bc7bea748 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Fri, 24 Aug 2018 13:27:10 +0300 Subject: [PATCH 65/82] Update file_helper.h --- include/spdlog/details/file_helper.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/spdlog/details/file_helper.h b/include/spdlog/details/file_helper.h index bca59420..08836566 100644 --- a/include/spdlog/details/file_helper.h +++ b/include/spdlog/details/file_helper.h @@ -5,7 +5,7 @@ #pragma once -// Helper class for file sink. +// Helper class for file sinks. // When failing to open a file, retry several times(5) with delay interval (10 ms). // Throw spdlog_ex exception on errors. From 1f8b2cbb8bf5882885797400967a66ba50736fc4 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Fri, 24 Aug 2018 13:27:49 +0300 Subject: [PATCH 66/82] Update file_helper.h --- include/spdlog/details/file_helper.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/spdlog/details/file_helper.h b/include/spdlog/details/file_helper.h index 08836566..f7282000 100644 --- a/include/spdlog/details/file_helper.h +++ b/include/spdlog/details/file_helper.h @@ -6,7 +6,7 @@ #pragma once // Helper class for file sinks. -// When failing to open a file, retry several times(5) with delay interval (10 ms). +// When failing to open a file, retry several times(5) with a delay interval(10 ms). // Throw spdlog_ex exception on errors. #include "spdlog/details/log_msg.h" From 91d8869f36195c062a07ea80bb3354f5195e6bf6 Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 25 Aug 2018 17:35:20 +0300 Subject: [PATCH 67/82] Added "clone()" support to loggers --- example/example.cpp | 13 ++++++++++++- include/spdlog/async_logger.h | 2 ++ include/spdlog/details/async_logger_impl.h | 14 ++++++++++++++ include/spdlog/details/logger_impl.h | 15 +++++++++++++++ include/spdlog/logger.h | 9 ++++++++- 5 files changed, 51 insertions(+), 2 deletions(-) diff --git a/example/example.cpp b/example/example.cpp index 4222c829..cfdc4e4e 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -18,6 +18,7 @@ void multi_sink_example(); void user_defined_example(); void err_handler_example(); void syslog_example(); +void clone_example(); #include "spdlog/spdlog.h" @@ -34,6 +35,8 @@ int main(int, char *[]) rotating_example(); daily_example(); + clone_example(); + // async logging using a backing thread pool async_example(); @@ -56,7 +59,7 @@ int main(int, char *[]) // release any threads created by spdlog, and drop all loggers in the registry. spdlog::shutdown(); } - // Exceptions will only be thrown upon failed logger or sink construction (not during logging) + // Exceptions will only be thrown upon failed logger or sink construction (not during logging) catch (const spdlog::spdlog_ex &ex) { std::cout << "Log init failed: " << ex.what() << std::endl; @@ -122,6 +125,14 @@ void daily_example() auto daily_logger = spdlog::daily_logger_mt("daily_logger", "logs/daily.txt", 2, 30); } +// clone a logger and give it new name. +// Useful for creating component/subsystem loggers from some "root" logger +void clone_example() +{ + auto network_logger = spdlog::get("console")->clone("network"); + network_logger->info("Logging network stuff.."); +} + #include "spdlog/async.h" void async_example() { diff --git a/include/spdlog/async_logger.h b/include/spdlog/async_logger.h index 3250f4ad..690b1c6a 100644 --- a/include/spdlog/async_logger.h +++ b/include/spdlog/async_logger.h @@ -55,6 +55,8 @@ public: async_logger(std::string logger_name, sink_ptr single_sink, std::weak_ptr tp, async_overflow_policy overflow_policy = async_overflow_policy::block); + std::shared_ptr clone(std::string new_name) override; + protected: void sink_it_(details::log_msg &msg) override; void flush_() override; diff --git a/include/spdlog/details/async_logger_impl.h b/include/spdlog/details/async_logger_impl.h index 47659ddc..27344815 100644 --- a/include/spdlog/details/async_logger_impl.h +++ b/include/spdlog/details/async_logger_impl.h @@ -98,3 +98,17 @@ inline void spdlog::async_logger::backend_flush_() } SPDLOG_CATCH_AND_HANDLE } + + +inline std::shared_ptr spdlog::async_logger::clone(std::string new_name) +{ + auto cloned = std::make_shared(std::move(new_name), + sinks_.begin(), sinks_.end(), + thread_pool_, + overflow_policy_); + + cloned->set_level(this->level()); + cloned->flush_on(this->flush_level()); + cloned->set_error_handler(this->error_handler()); + return std::move(cloned); +} \ No newline at end of file diff --git a/include/spdlog/details/logger_impl.h b/include/spdlog/details/logger_impl.h index 1451adc6..82d901da 100644 --- a/include/spdlog/details/logger_impl.h +++ b/include/spdlog/details/logger_impl.h @@ -271,6 +271,12 @@ inline void spdlog::logger::flush_on(level::level_enum log_level) flush_level_.store(log_level); } +inline spdlog::level::level_enum spdlog::logger::flush_level() const +{ + return static_cast(flush_level_.load(std::memory_order_relaxed)); +} + + inline bool spdlog::logger::should_flush_(const details::log_msg &msg) { auto flush_level = flush_level_.load(std::memory_order_relaxed); @@ -346,3 +352,12 @@ inline std::vector &spdlog::logger::sinks() { return sinks_; } + +inline std::shared_ptr spdlog::logger::clone(std::string logger_name) +{ + auto cloned = std::make_shared(std::move(logger_name), sinks_.begin(), sinks_.end()); + cloned->set_level(this->level()); + cloned->flush_on(this->flush_level()); + cloned->set_error_handler(this->error_handler()); + return std::move(cloned); +} \ No newline at end of file diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index 91eec4bc..b3dcb7ae 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -115,21 +115,28 @@ public: level::level_enum level() const; const std::string &name() const; + // set formatting for the sinks in this logger. // each sink will get a seperate instance of the formatter object. void set_formatter(std::unique_ptr formatter); void set_pattern(std::string pattern, pattern_time_type time_type = pattern_time_type::local); + // flush functions void flush(); void flush_on(level::level_enum log_level); + level::level_enum flush_level() const; + // sinks const std::vector &sinks() const; - std::vector &sinks(); + // error handler void set_error_handler(log_err_handler err_handler); log_err_handler error_handler(); + // create new logger with same sinks and configuration. + virtual std::shared_ptr clone(std::string logger_name); + protected: virtual void sink_it_(details::log_msg &msg); virtual void flush_(); From 5d7845c13891effcd1bc921540529c2fb23d74ae Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 25 Aug 2018 17:55:31 +0300 Subject: [PATCH 68/82] Added "clone()" support to loggers --- README.md | 12 ++++++++++++ example/example.cpp | 2 +- include/spdlog/details/async_logger_impl.h | 6 +----- include/spdlog/details/fmt_helper.h | 4 ++-- include/spdlog/details/logger_impl.h | 6 ++---- include/spdlog/logger.h | 1 - tests/includes.h | 2 +- tests/test_mpmc_q.cpp | 5 ++--- 8 files changed, 21 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index ca797e14..89a7cddd 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,18 @@ void daily_example() --- #### Periodic flush ```c++ +// clone a logger and give it new name. +// Useful for creating subsystem loggers from some "root" logger +void clone_example() +{ + auto network_logger = spdlog::get("console")->clone("network"); + network_logger->info("Logging network stuff.."); +} +``` + +--- +#### Cloning loggers for +```c++ // periodically flush all *registered* loggers every 3 seconds: // warning: only use if all your loggers are thread safe! spdlog::flush_every(std::chrono::seconds(3)); diff --git a/example/example.cpp b/example/example.cpp index cfdc4e4e..b7221447 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -59,7 +59,7 @@ int main(int, char *[]) // release any threads created by spdlog, and drop all loggers in the registry. spdlog::shutdown(); } - // Exceptions will only be thrown upon failed logger or sink construction (not during logging) + // Exceptions will only be thrown upon failed logger or sink construction (not during logging) catch (const spdlog::spdlog_ex &ex) { std::cout << "Log init failed: " << ex.what() << std::endl; diff --git a/include/spdlog/details/async_logger_impl.h b/include/spdlog/details/async_logger_impl.h index 27344815..b6e86460 100644 --- a/include/spdlog/details/async_logger_impl.h +++ b/include/spdlog/details/async_logger_impl.h @@ -99,13 +99,9 @@ inline void spdlog::async_logger::backend_flush_() SPDLOG_CATCH_AND_HANDLE } - inline std::shared_ptr spdlog::async_logger::clone(std::string new_name) { - auto cloned = std::make_shared(std::move(new_name), - sinks_.begin(), sinks_.end(), - thread_pool_, - overflow_policy_); + auto cloned = std::make_shared(std::move(new_name), sinks_.begin(), sinks_.end(), thread_pool_, overflow_policy_); cloned->set_level(this->level()); cloned->flush_on(this->flush_level()); diff --git a/include/spdlog/details/fmt_helper.h b/include/spdlog/details/fmt_helper.h index 76a00b4c..1d84e5eb 100644 --- a/include/spdlog/details/fmt_helper.h +++ b/include/spdlog/details/fmt_helper.h @@ -22,8 +22,8 @@ inline void append_str(const std::string &str, fmt::basic_memory_buffer inline void append_c_str(const char *c_str, fmt::basic_memory_buffer &dest) { - auto len = std::char_traits::length(c_str); - dest.append(c_str, c_str + len); + auto len = std::char_traits::length(c_str); + dest.append(c_str, c_str + len); } template diff --git a/include/spdlog/details/logger_impl.h b/include/spdlog/details/logger_impl.h index 82d901da..76daac35 100644 --- a/include/spdlog/details/logger_impl.h +++ b/include/spdlog/details/logger_impl.h @@ -10,7 +10,6 @@ #include #include - // create logger with given name, sinks and the default pattern formatter // all other ctors will call this one template @@ -79,8 +78,8 @@ inline void spdlog::logger::log(level::level_enum lvl, const char *msg) } try { - details::log_msg log_msg(&name_, lvl); - details::fmt_helper::append_c_str(msg, log_msg.raw); + details::log_msg log_msg(&name_, lvl); + details::fmt_helper::append_c_str(msg, log_msg.raw); sink_it_(log_msg); } SPDLOG_CATCH_AND_HANDLE @@ -276,7 +275,6 @@ inline spdlog::level::level_enum spdlog::logger::flush_level() const return static_cast(flush_level_.load(std::memory_order_relaxed)); } - inline bool spdlog::logger::should_flush_(const details::log_msg &msg) { auto flush_level = flush_level_.load(std::memory_order_relaxed); diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index b3dcb7ae..aa524f70 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -115,7 +115,6 @@ public: level::level_enum level() const; const std::string &name() const; - // set formatting for the sinks in this logger. // each sink will get a seperate instance of the formatter object. void set_formatter(std::unique_ptr formatter); diff --git a/tests/includes.h b/tests/includes.h index 4d35d6b8..bce67418 100644 --- a/tests/includes.h +++ b/tests/includes.h @@ -6,8 +6,8 @@ #include #include #include -#include #include +#include #include #define SPDLOG_TRACE_ON diff --git a/tests/test_mpmc_q.cpp b/tests/test_mpmc_q.cpp index ddb31961..7c56496d 100644 --- a/tests/test_mpmc_q.cpp +++ b/tests/test_mpmc_q.cpp @@ -2,12 +2,11 @@ using namespace std::chrono; using std::chrono::milliseconds; -using test_clock = std::chrono::high_resolution_clock ; - +using test_clock = std::chrono::high_resolution_clock; static milliseconds millis_from(const test_clock::time_point &tp0) { - return std::chrono::duration_cast(test_clock::now()-tp0); + return std::chrono::duration_cast(test_clock::now() - tp0); } TEST_CASE("dequeue-empty-nowait", "[mpmc_blocking_q]") { From 447a6a15d93d4fac92c335253c335a1e0ff68e9d Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 25 Aug 2018 17:57:41 +0300 Subject: [PATCH 69/82] Fixed readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 89a7cddd..b79812a3 100644 --- a/README.md +++ b/README.md @@ -159,7 +159,7 @@ void daily_example() ``` --- -#### Periodic flush +#### Cloning loggers ```c++ // clone a logger and give it new name. // Useful for creating subsystem loggers from some "root" logger @@ -171,7 +171,7 @@ void clone_example() ``` --- -#### Cloning loggers for +#### Periodic flush ```c++ // periodically flush all *registered* loggers every 3 seconds: // warning: only use if all your loggers are thread safe! From 6c5bbca0c1e5e716e13781674e8a8fe3250d0f38 Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 25 Aug 2018 18:10:42 +0300 Subject: [PATCH 70/82] Added clone tests --- README.md | 2 +- tests/test_misc.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b79812a3..0bf357b7 100644 --- a/README.md +++ b/README.md @@ -159,7 +159,7 @@ void daily_example() ``` --- -#### Cloning loggers +#### Cloning loggers ```c++ // clone a logger and give it new name. // Useful for creating subsystem loggers from some "root" logger diff --git a/tests/test_misc.cpp b/tests/test_misc.cpp index 2de4fb26..7bdfa881 100644 --- a/tests/test_misc.cpp +++ b/tests/test_misc.cpp @@ -91,3 +91,48 @@ TEST_CASE("periodic flush", "[periodic_flush]") spdlog::flush_every(std::chrono::seconds(0)); spdlog::drop_all(); } + + +TEST_CASE("clone", "[clone]") +{ + using namespace spdlog; + + auto logger = spdlog::create("orig"); + auto cloned = logger->clone("clone"); + + REQUIRE(cloned->name() == "clone"); + REQUIRE(logger->sinks() == cloned->sinks()); + REQUIRE(logger->level() == cloned->level()); + REQUIRE(logger->flush_level() == cloned->flush_level()); + logger->info("Some message 1"); + cloned->info("Some message 2"); + + auto test_sink = std::static_pointer_cast(cloned->sinks()[0]); + REQUIRE(test_sink->msg_counter() == 2); + + spdlog::drop_all(); +} + +TEST_CASE("clone async", "[clone]") +{ + using namespace spdlog; + + auto logger = spdlog::create_async("orig"); + auto cloned = logger->clone("clone"); + + REQUIRE(cloned->name() == "clone"); + REQUIRE(logger->sinks() == cloned->sinks()); + REQUIRE(logger->level() == cloned->level()); + REQUIRE(logger->flush_level() == cloned->flush_level()); + + logger->info("Some message 1"); + cloned->info("Some message 2"); + + spdlog::details::os::sleep_for_millis(10); + + auto test_sink = std::static_pointer_cast(cloned->sinks()[0]); + REQUIRE(test_sink->msg_counter() == 2); + + + spdlog::drop_all(); +} From c4de214cea84886aea919cd7c9ce9aa522118bab Mon Sep 17 00:00:00 2001 From: Maciej Gajewski Date: Wed, 29 Aug 2018 17:21:38 +0200 Subject: [PATCH 71/82] Pessimizing move removed --- include/spdlog/details/logger_impl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/spdlog/details/logger_impl.h b/include/spdlog/details/logger_impl.h index 76daac35..7291e631 100644 --- a/include/spdlog/details/logger_impl.h +++ b/include/spdlog/details/logger_impl.h @@ -357,5 +357,5 @@ inline std::shared_ptr spdlog::logger::clone(std::string logger_ cloned->set_level(this->level()); cloned->flush_on(this->flush_level()); cloned->set_error_handler(this->error_handler()); - return std::move(cloned); -} \ No newline at end of file + return cloned; +} From 679fcd787f9e51c38157e9644499f91e14019c51 Mon Sep 17 00:00:00 2001 From: Jeremy Nimmer Date: Wed, 29 Aug 2018 12:29:32 -0400 Subject: [PATCH 72/82] Add set_sinks method to dist_sink This allows users to set exactly the sinks they want, even if other unknown application code has added bespoke sinks in the meantime. --- include/spdlog/sinks/dist_sink.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/spdlog/sinks/dist_sink.h b/include/spdlog/sinks/dist_sink.h index 8d2f6f9e..b3e2e525 100644 --- a/include/spdlog/sinks/dist_sink.h +++ b/include/spdlog/sinks/dist_sink.h @@ -40,6 +40,12 @@ public: sinks_.erase(std::remove(sinks_.begin(), sinks_.end(), sink), sinks_.end()); } + void set_sinks(std::vector> sinks) + { + std::lock_guard lock(base_sink::mutex_); + sinks_ = std::move(sinks); + } + protected: void sink_it_(const details::log_msg &msg) override { From e52e258f151a7324ea14828c5617aadde35571c3 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Fri, 31 Aug 2018 04:14:23 +0300 Subject: [PATCH 73/82] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0bf357b7..3f84b2f6 100644 --- a/README.md +++ b/README.md @@ -165,7 +165,7 @@ void daily_example() // Useful for creating subsystem loggers from some "root" logger void clone_example() { - auto network_logger = spdlog::get("console")->clone("network"); + auto network_logger = spdlog::get("root")->clone("network"); network_logger->info("Logging network stuff.."); } ``` From f4bbe8b2b3ebe538afe3aa45f054be588051fb4e Mon Sep 17 00:00:00 2001 From: gabime Date: Fri, 31 Aug 2018 14:17:11 +0300 Subject: [PATCH 74/82] Fixed some extra warnings from clang --- example/Makefile-all-warn | 22 ++++++++++++++++++++++ include/spdlog/details/async_logger_impl.h | 2 +- include/spdlog/details/thread_pool.h | 18 +++++++++--------- include/spdlog/sinks/sink.h | 4 +++- tests/test_misc.cpp | 2 -- 5 files changed, 35 insertions(+), 13 deletions(-) create mode 100644 example/Makefile-all-warn diff --git a/example/Makefile-all-warn b/example/Makefile-all-warn new file mode 100644 index 00000000..2ba68e2a --- /dev/null +++ b/example/Makefile-all-warn @@ -0,0 +1,22 @@ +#-Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded +CXX ?= g++ +CXX_FLAGS = -Wall -Wextra -pedantic -std=c++11 -pthread -I../include -fmax-errors=1 -Wconversion -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-weak-vtables -Wno-global-constructors +CXX_RELEASE_FLAGS = -O3 -march=native +CXX_DEBUG_FLAGS= -g + +all: example +debug: example-debug + +example: example.cpp + $(CXX) example.cpp -o example $(CXX_FLAGS) $(CXX_RELEASE_FLAGS) $(CXXFLAGS) + + +example-debug: example.cpp + $(CXX) example.cpp -o example-debug $(CXX_FLAGS) $(CXX_DEBUG_FLAGS) $(CXXFLAGS) + +clean: + rm -f *.o logs/*.txt example example-debug + + +rebuild: clean all +rebuild-debug: clean debug diff --git a/include/spdlog/details/async_logger_impl.h b/include/spdlog/details/async_logger_impl.h index b6e86460..3ad70a3b 100644 --- a/include/spdlog/details/async_logger_impl.h +++ b/include/spdlog/details/async_logger_impl.h @@ -107,4 +107,4 @@ inline std::shared_ptr spdlog::async_logger::clone(std::string n cloned->flush_on(this->flush_level()); cloned->set_error_handler(this->error_handler()); return std::move(cloned); -} \ No newline at end of file +} diff --git a/include/spdlog/details/thread_pool.h b/include/spdlog/details/thread_pool.h index 282d67e8..29f5d9d4 100644 --- a/include/spdlog/details/thread_pool.h +++ b/include/spdlog/details/thread_pool.h @@ -198,6 +198,13 @@ private: switch (incoming_async_msg.msg_type) { + case async_msg_type::log: + { + log_msg msg; + incoming_async_msg.to_log_msg(msg); + incoming_async_msg.worker_ptr->backend_log_(msg); + return true; + } case async_msg_type::flush: { incoming_async_msg.worker_ptr->backend_flush_(); @@ -208,16 +215,9 @@ private: { return false; } - - default: - { - log_msg msg; - incoming_async_msg.to_log_msg(msg); - incoming_async_msg.worker_ptr->backend_log_(msg); - return true; } - } - return true; // should not be reached + assert(false && "Unexpected async_msg_type"); + return true; } }; diff --git a/include/spdlog/sinks/sink.h b/include/spdlog/sinks/sink.h index cb8aecb4..9f84c378 100644 --- a/include/spdlog/sinks/sink.h +++ b/include/spdlog/sinks/sink.h @@ -22,7 +22,9 @@ public: explicit sink(std::unique_ptr formatter) : level_(level::trace) - , formatter_(std::move(formatter)){}; + , formatter_(std::move(formatter)) + { + } virtual ~sink() = default; virtual void log(const details::log_msg &msg) = 0; diff --git a/tests/test_misc.cpp b/tests/test_misc.cpp index 7bdfa881..f1fb80e9 100644 --- a/tests/test_misc.cpp +++ b/tests/test_misc.cpp @@ -92,7 +92,6 @@ TEST_CASE("periodic flush", "[periodic_flush]") spdlog::drop_all(); } - TEST_CASE("clone", "[clone]") { using namespace spdlog; @@ -133,6 +132,5 @@ TEST_CASE("clone async", "[clone]") auto test_sink = std::static_pointer_cast(cloned->sinks()[0]); REQUIRE(test_sink->msg_counter() == 2); - spdlog::drop_all(); } From ebce97947da13d7637a975ac9e048a173d1b9530 Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 1 Sep 2018 21:30:05 +0300 Subject: [PATCH 75/82] use make_unique --- include/spdlog/common.h | 13 ++++ include/spdlog/details/pattern_formatter.h | 75 +++++++++++----------- include/spdlog/details/registry.h | 2 +- 3 files changed, 51 insertions(+), 39 deletions(-) diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 1542fa92..379a6d75 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -174,4 +174,17 @@ using filename_t = std::string; { \ err_handler_("Unknown exeption in logger"); \ } + +// +// make_unique support +// +#if __cplusplus >= 201402L // C++14 and beyond +using std::make_unique; +#else +template +std::unique_ptr make_unique(Args &&... args) +{ + return std::unique_ptr(new T(std::forward(args)...)); +} +#endif } // namespace spdlog diff --git a/include/spdlog/details/pattern_formatter.h b/include/spdlog/details/pattern_formatter.h index dd352ae5..2d73cacf 100644 --- a/include/spdlog/details/pattern_formatter.h +++ b/include/spdlog/details/pattern_formatter.h @@ -547,7 +547,7 @@ public: std::unique_ptr clone() const override { - return std::unique_ptr(new pattern_formatter(pattern_, pattern_time_type_, eol_)); + return spdlog::make_unique(pattern_, pattern_time_type_, eol_); } void format(const details::log_msg &msg, fmt::memory_buffer &dest) override @@ -588,146 +588,145 @@ private: void handle_flag_(char flag) { - using flag_formatter_ptr = std::unique_ptr; switch (flag) { // logger name case 'n': - formatters_.push_back(flag_formatter_ptr(new details::name_formatter())); + formatters_.push_back(make_unique()); break; case 'l': - formatters_.push_back(flag_formatter_ptr(new details::level_formatter())); + formatters_.push_back(make_unique()); break; case 'L': - formatters_.push_back(flag_formatter_ptr(new details::short_level_formatter())); + formatters_.push_back(make_unique()); break; case ('t'): - formatters_.push_back(flag_formatter_ptr(new details::t_formatter())); + formatters_.push_back(make_unique()); break; case ('v'): - formatters_.push_back(flag_formatter_ptr(new details::v_formatter())); + formatters_.push_back(make_unique()); break; case ('a'): - formatters_.push_back(flag_formatter_ptr(new details::a_formatter())); + formatters_.push_back(make_unique()); break; case ('A'): - formatters_.push_back(flag_formatter_ptr(new details::A_formatter())); + formatters_.push_back(make_unique()); break; case ('b'): case ('h'): - formatters_.push_back(flag_formatter_ptr(new details::b_formatter())); + formatters_.push_back(make_unique()); break; case ('B'): - formatters_.push_back(flag_formatter_ptr(new details::B_formatter())); + formatters_.push_back(make_unique()); break; case ('c'): - formatters_.push_back(flag_formatter_ptr(new details::c_formatter())); + formatters_.push_back(make_unique()); break; case ('C'): - formatters_.push_back(flag_formatter_ptr(new details::C_formatter())); + formatters_.push_back(make_unique()); break; case ('Y'): - formatters_.push_back(flag_formatter_ptr(new details::Y_formatter())); + formatters_.push_back(make_unique()); break; case ('D'): case ('x'): - formatters_.push_back(flag_formatter_ptr(new details::D_formatter())); + formatters_.push_back(make_unique()); break; case ('m'): - formatters_.push_back(flag_formatter_ptr(new details::m_formatter())); + formatters_.push_back(make_unique()); break; case ('d'): - formatters_.push_back(flag_formatter_ptr(new details::d_formatter())); + formatters_.push_back(make_unique()); break; case ('H'): - formatters_.push_back(flag_formatter_ptr(new details::H_formatter())); + formatters_.push_back(make_unique()); break; case ('I'): - formatters_.push_back(flag_formatter_ptr(new details::I_formatter())); + formatters_.push_back(make_unique()); break; case ('M'): - formatters_.push_back(flag_formatter_ptr(new details::M_formatter())); + formatters_.push_back(make_unique()); break; case ('S'): - formatters_.push_back(flag_formatter_ptr(new details::S_formatter())); + formatters_.push_back(make_unique()); break; case ('e'): - formatters_.push_back(flag_formatter_ptr(new details::e_formatter())); + formatters_.push_back(make_unique()); break; case ('f'): - formatters_.push_back(flag_formatter_ptr(new details::f_formatter())); + formatters_.push_back(make_unique()); break; case ('F'): - formatters_.push_back(flag_formatter_ptr(new details::F_formatter())); + formatters_.push_back(make_unique()); break; case ('E'): - formatters_.push_back(flag_formatter_ptr(new details::E_formatter())); + formatters_.push_back(make_unique()); break; case ('p'): - formatters_.push_back(flag_formatter_ptr(new details::p_formatter())); + formatters_.push_back(make_unique()); break; case ('r'): - formatters_.push_back(flag_formatter_ptr(new details::r_formatter())); + formatters_.push_back(make_unique()); break; case ('R'): - formatters_.push_back(flag_formatter_ptr(new details::R_formatter())); + formatters_.push_back(make_unique()); break; case ('T'): case ('X'): - formatters_.push_back(flag_formatter_ptr(new details::T_formatter())); + formatters_.push_back(make_unique()); break; case ('z'): - formatters_.push_back(flag_formatter_ptr(new details::z_formatter())); + formatters_.push_back(make_unique()); break; case ('+'): - formatters_.push_back(flag_formatter_ptr(new details::full_formatter())); + formatters_.push_back(make_unique()); break; case ('P'): - formatters_.push_back(flag_formatter_ptr(new details::pid_formatter())); + formatters_.push_back(make_unique()); break; case ('i'): - formatters_.push_back(flag_formatter_ptr(new details::i_formatter())); + formatters_.push_back(make_unique()); break; case ('^'): - formatters_.push_back(flag_formatter_ptr(new details::color_start_formatter())); + formatters_.push_back(make_unique()); break; case ('$'): - formatters_.push_back(flag_formatter_ptr(new details::color_stop_formatter())); + formatters_.push_back(make_unique()); break; default: // Unknown flag appears as is - formatters_.push_back(flag_formatter_ptr(new details::ch_formatter('%'))); - formatters_.push_back(flag_formatter_ptr(new details::ch_formatter(flag))); + formatters_.push_back(make_unique('%')); + formatters_.push_back(make_unique(flag)); break; } } @@ -758,7 +757,7 @@ private: { if (!user_chars) { - user_chars = std::unique_ptr(new details::aggregate_formatter()); + user_chars = spdlog::make_unique(); } user_chars->add_ch(*it); } diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/registry.h index 3988552a..bbe083e2 100644 --- a/include/spdlog/details/registry.h +++ b/include/spdlog/details/registry.h @@ -113,7 +113,7 @@ public: { std::lock_guard lock(flusher_mutex_); std::function clbk = std::bind(®istry::flush_all, this); - periodic_flusher_.reset(new periodic_worker(clbk, interval)); + periodic_flusher_ = make_unique(clbk, interval); } void set_error_handler(log_err_handler handler) From a6ee1cf5905100e780aa43261dbb2c716103a22e Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Sat, 1 Sep 2018 21:56:19 +0300 Subject: [PATCH 76/82] fix vc compliation error about make_unique --- include/spdlog/details/registry.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/registry.h index bbe083e2..2016e341 100644 --- a/include/spdlog/details/registry.h +++ b/include/spdlog/details/registry.h @@ -16,7 +16,7 @@ #include #include -#include +#include #include @@ -113,7 +113,7 @@ public: { std::lock_guard lock(flusher_mutex_); std::function clbk = std::bind(®istry::flush_all, this); - periodic_flusher_ = make_unique(clbk, interval); + periodic_flusher_ = spdlog::make_unique(clbk, interval); } void set_error_handler(log_err_handler handler) From 00acb8ba41a006f94fc1ed0fcb8b97d494d6e7ae Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Sat, 1 Sep 2018 22:41:56 +0300 Subject: [PATCH 77/82] Update registry.h --- include/spdlog/details/registry.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/registry.h index 2016e341..52c3bb7d 100644 --- a/include/spdlog/details/registry.h +++ b/include/spdlog/details/registry.h @@ -16,7 +16,7 @@ #include #include -#include #include #include From 3698c1d2f188c6092c663294b9f3348472bed3f2 Mon Sep 17 00:00:00 2001 From: gabime Date: Sun, 2 Sep 2018 01:27:28 +0300 Subject: [PATCH 78/82] added spdlog namespace when calling make_unique --- include/spdlog/details/pattern_formatter.h | 70 +++++++++++----------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/include/spdlog/details/pattern_formatter.h b/include/spdlog/details/pattern_formatter.h index 2d73cacf..ecdabff3 100644 --- a/include/spdlog/details/pattern_formatter.h +++ b/include/spdlog/details/pattern_formatter.h @@ -592,141 +592,141 @@ private: { // logger name case 'n': - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case 'l': - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case 'L': - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case ('t'): - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case ('v'): - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case ('a'): - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case ('A'): - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case ('b'): case ('h'): - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case ('B'): - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case ('c'): - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case ('C'): - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case ('Y'): - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case ('D'): case ('x'): - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case ('m'): - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case ('d'): - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case ('H'): - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case ('I'): - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case ('M'): - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case ('S'): - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case ('e'): - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case ('f'): - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case ('F'): - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case ('E'): - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case ('p'): - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case ('r'): - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case ('R'): - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case ('T'): case ('X'): - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case ('z'): - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case ('+'): - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case ('P'): - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case ('i'): - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case ('^'): - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; case ('$'): - formatters_.push_back(make_unique()); + formatters_.push_back(spdlog::make_unique()); break; default: // Unknown flag appears as is - formatters_.push_back(make_unique('%')); - formatters_.push_back(make_unique(flag)); + formatters_.push_back(spdlog::make_unique('%')); + formatters_.push_back(spdlog::make_unique(flag)); break; } } From 37cd70729488389b590dd8bf5f2137e8b08cf217 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Mon, 3 Sep 2018 19:08:57 +0300 Subject: [PATCH 79/82] Fix issue #819 --- include/spdlog/details/thread_pool.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/spdlog/details/thread_pool.h b/include/spdlog/details/thread_pool.h index 29f5d9d4..b7eb6caa 100644 --- a/include/spdlog/details/thread_pool.h +++ b/include/spdlog/details/thread_pool.h @@ -64,8 +64,8 @@ struct async_msg return *this; } #else // (_MSC_VER) && _MSC_VER <= 1800 - async_msg(async_msg &&other) = default; - async_msg &operator=(async_msg &&other) = default; + async_msg(async_msg &&) = default; + async_msg &operator=(async_msg &&) = default; #endif // construct from log_msg with given type From bcc6db4a06caedad306a3eb3b198b5a03d8f1cdc Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Tue, 4 Sep 2018 19:34:59 +0300 Subject: [PATCH 80/82] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3f84b2f6..a8fa9c20 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ Very fast, header only, C++ logging library. [![Build Status](https://travis-ci.org/gabime/spdlog.svg?branch=master)](https://travis-ci.org/gabime/spdlog)  [![Build status](https://ci.appveyor.com/api/projects/status/d2jnxclg20vd0o50?svg=true)](https://ci.appveyor.com/project/gabime/spdlog) + ## Install #### Just copy the headers: From 18efcd62fffa1e0e0c096c5fdb9d982cab658441 Mon Sep 17 00:00:00 2001 From: Elmar Pruesse Date: Wed, 5 Sep 2018 19:25:11 -0600 Subject: [PATCH 81/82] Add `conda` to package managers in README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a8fa9c20..ec16b943 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Very fast, header only, C++ logging library. [![Build Status](https://travis-ci. * Gentoo: `emerge dev-libs/spdlog` * Arch Linux: `yaourt -S spdlog-git` * vcpkg: `vcpkg install spdlog` +* Conda: `conda install -c conda-forge spdlog` ## Platforms From 1aa4b657d61b30857f8fefb9888ec658fce7c293 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Thu, 6 Sep 2018 13:30:25 +0300 Subject: [PATCH 82/82] Revert "Add `conda` to package managers in README" --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index ec16b943..a8fa9c20 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,6 @@ Very fast, header only, C++ logging library. [![Build Status](https://travis-ci. * Gentoo: `emerge dev-libs/spdlog` * Arch Linux: `yaourt -S spdlog-git` * vcpkg: `vcpkg install spdlog` -* Conda: `conda install -c conda-forge spdlog` ## Platforms