Compare commits

...

10 Commits

Author SHA1 Message Date
Gabi Melman 6491abb519
Update .travis.yml 2021-07-10 19:14:47 +03:00
gabime 8faabb4e3a Fix msvc compile 2021-07-10 17:33:08 +03:00
gabime 2838c2c8a5 use vformat_to instead for format_to for better performance 2021-07-10 17:00:13 +03:00
gabime 3315bad009 Treat wall warnings as errors if SPDLOG_BUILD_WARNINGS is ON 2021-07-10 15:22:44 +03:00
gabime 3eeced78b5 Removed some cmake wdev warnings 2021-07-10 15:15:39 +03:00
gabime c23430b438 Fixed cast warning 2021-07-10 14:31:56 +03:00
Gabi Melman 0e49bfff51
Update .travis.yml 2021-07-10 14:20:06 +03:00
Gabi Melman 3ed40d04a9
Update .travis.yml 2021-07-10 14:14:09 +03:00
gabime 70b36aa55d Remove fmt::runtime() wrapper in logger.h 2021-07-10 14:07:32 +03:00
gabime 0f83b33d4f backward compatibility with fmt version < 8 2021-07-10 13:48:06 +03:00
8 changed files with 72 additions and 59 deletions

View File

@ -21,6 +21,16 @@ addons: &gcc7
sources:
- ubuntu-toolchain-r-test
# gcc 9.0
addons: &gcc9
apt:
packages:
- g++-9
sources:
- ubuntu-toolchain-r-test
# Clang 3.5
addons: &clang35
apt:
@ -44,48 +54,42 @@ addons: &clang10
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
# Test gcc-4.8: C++11, Build=Release
- env: GCC_VERSION=4.8 BUILD_TYPE=Release CPP=11
os: linux
addons: *gcc48
# Test gcc-7: C++11, Build=Debug/Release
# Test gcc-7: C++11, Build=Release
- 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
# Test gcc-9: C++17, Build=Release
- env: GCC_VERSION=9 BUILD_TYPE=Release CPP=17
os: linux
addons: *clang35
addons: *gcc9
# Test clang-3.5: C++11, Build=Release
- env: CLANG_VERSION=3.5 BUILD_TYPE=Release CPP=11
os: linux
addons: *clang35
# osx
# Text osx
- env: BUILD_TYPE=Release CPP=11 ASAN=Off TSAN=Off
os: osx
# Test clang-10.0: C++11, Build=Debug/Release
- env: CLANG_VERSION=10 BUILD_TYPE=Debug CPP=11
os: linux
dist: bionic
addons: *clang10
# Test clang-10.0: C++11, Build=Release
- env: CLANG_VERSION=10 BUILD_TYPE=Release CPP=11 ASAN=On
os: linux
dist: bionic
addons: *clang10
# Test clang-10.0: C++17, Build=Debug/Release
- env: CLANG_VERSION=10 BUILD_TYPE=Release CPP=17 ASAN=Off
# Test clang-10.0: C++17, Build=Debug
- env: CLANG_VERSION=10 BUILD_TYPE=Debug CPP=17 ASAN=Off
os: linux
dist: bionic
addons: *clang10
before_script:

View File

@ -99,10 +99,15 @@ endif ()
if (WIN32)
option(SPDLOG_WCHAR_SUPPORT "Support wchar api" OFF)
option(SPDLOG_WCHAR_FILENAMES "Support wchar filenames" OFF)
else ()
SET(SPDLOG_WCHAR_SUPPORT OFF CACHE BOOL "non supported option" FORCE)
SET(SPDLOG_WCHAR_FILENAMES OFF CACHE BOOL "non supported option" FORCE)
endif ()
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
option(SPDLOG_CLOCK_COARSE
"Use the much faster (but much less accurate) CLOCK_REALTIME_COARSE instead of the regular clock," OFF)
option(SPDLOG_CLOCK_COARSE "Use CLOCK_REALTIME_COARSE instead of the regular clock," OFF)
else ()
SET(SPDLOG_CLOCK_COARSE OFF CACHE BOOL "non supported option" FORCE)
endif ()
option(SPDLOG_PREVENT_CHILD_FD "Prevent from child processes to inherit log file descriptors" OFF)

View File

@ -103,12 +103,11 @@ int main(int argc, char *argv[])
auto slot_size = sizeof(spdlog::details::async_msg);
spdlog::info("-------------------------------------------------");
spdlog::info(fmt::format(std::locale("en_US.UTF-8"), "Messages : {:L}", howmany));
spdlog::info(fmt::format(std::locale("en_US.UTF-8"), "Threads : {:L}", threads));
spdlog::info(fmt::format(std::locale("en_US.UTF-8"), "Queue : {:L} slots", queue_size));
spdlog::info(fmt::format(
std::locale("en_US.UTF-8"), "Queue memory : {:L} x {:L} = {:L} KB ", queue_size, slot_size, (queue_size * slot_size) / 1024));
spdlog::info(fmt::format(std::locale("en_US.UTF-8"), "Total iters : {:L}", iters));
spdlog::info("Messages : {:L}", howmany);
spdlog::info("Threads : {:L}", threads);
spdlog::info("Queue : {:L} slots", queue_size);
spdlog::info("Queue memory : {:L} x {:L} = {:L} KB ", queue_size, slot_size, (queue_size * slot_size) / 1024);
spdlog::info("Total iters : {:L}", iters);
spdlog::info("-------------------------------------------------");
const char *filename = "logs/basic_async.log";
@ -181,5 +180,5 @@ void bench_mt(int howmany, std::shared_ptr<spdlog::logger> logger, int thread_co
auto delta = high_resolution_clock::now() - start;
auto delta_d = duration_cast<duration<double>>(delta).count();
spdlog::info(fmt::format(std::locale("en_US.UTF-8"), "Elapsed: {} secs\t {:L}/sec", delta_d, int(howmany / delta_d)));
spdlog::info("Elapsed: {} secs\t {:L}/sec", delta_d, int(howmany / delta_d));
}

View File

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

View File

@ -35,8 +35,14 @@
#include <spdlog/fmt/fmt.h>
#if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT)
# include <spdlog/fmt/xchar.h>
// backward compatibility with fmt versions older than 8
#if FMT_VERSION >= 80000
# define SPDLOG_FMT_RUNTIME(format_string) fmt::runtime(format_string)
# if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT)
# include <spdlog/fmt/xchar.h>
# endif
#else
# define SPDLOG_FMT_RUNTIME(format_string) format_string
#endif
// visual studio upto 2013 does not support noexcept nor constexpr

View File

@ -23,7 +23,6 @@
#endif
#include <vector>
#include <iterator>
#ifndef SPDLOG_NO_EXCEPTIONS
# define SPDLOG_LOGGER_CATCH() \
@ -239,10 +238,8 @@ public:
SPDLOG_TRY
{
// format to wmemory_buffer and convert to utf8
fmt::wmemory_buffer wbuf;
fmt::format_to(std::back_inserter(wbuf), fmt, std::forward<Args>(args)...);
memory_buf_t buf;
details::os::wstr_to_utf8buf(wstring_view_t(wbuf.data(), wbuf.size()), buf);
details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size()));
@ -341,7 +338,8 @@ protected:
SPDLOG_TRY
{
memory_buf_t buf;
fmt::format_to(std::back_inserter(buf), fmt::runtime(fmt), std::forward<Args>(args)...);
// faster than fmt::format_to(std::back_inserter(buf), fmt, std::forward<Args>(args)...);
fmt::detail::vformat_to(buf, fmt::string_view(fmt), fmt::make_format_args(args...), {});
details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size()));
log_it_(log_msg, log_enabled, traceback_enabled);
}

View File

@ -53,7 +53,7 @@ struct daily_filename_format_calculator
#if defined(_MSC_VER) && defined(SPDLOG_WCHAR_FILENAMES) // for some reason msvc doesnt allow fmt::runtime(..) with wchar here
return fmt::format(fmt_filename, now_tm);
#else
return fmt::format(fmt::runtime(fmt_filename), now_tm);
return fmt::format(SPDLOG_FMT_RUNTIME(fmt_filename), now_tm);
#endif
}
};

View File

@ -62,10 +62,10 @@ protected:
// log the "skipped.." message
if (skip_counter_ > 0)
{
{
char buf[64];
auto msg_size = ::snprintf(buf, sizeof(buf), "Skipped %u duplicate messages..", static_cast<unsigned>(skip_counter_));
if (msg_size > 0 && msg_size < sizeof(buf))
if (msg_size > 0 && static_cast<size_t>(msg_size) < sizeof(buf))
{
details::log_msg skipped_msg{msg.logger_name, level::info, string_view_t{buf, static_cast<size_t>(msg_size)}};
dist_sink<Mutex>::sink_it_(skipped_msg);