Merge branch 'v1.x' of github.com:gabime/spdlog into v1.x

pull/1216/head
Stefano Caiazza 6 years ago
commit 3d2d7a8748

@ -87,8 +87,6 @@ set(SPDLOG_SRCS
src/file_sinks.cpp src/file_sinks.cpp
src/async.cpp) src/async.cpp)
set(SPDLOG_CFLAGS "${PROJECT_NAME}")
if (SPDLOG_BUILD_SHARED) if (SPDLOG_BUILD_SHARED)
if(WIN32) if(WIN32)
message(FATAL_ERROR "spdlog shared lib is not yet supported under windows") message(FATAL_ERROR "spdlog shared lib is not yet supported under windows")
@ -129,14 +127,13 @@ if(SPDLOG_FMT_EXTERNAL)
if (NOT TARGET fmt::fmt) if (NOT TARGET fmt::fmt)
find_package(fmt REQUIRED) find_package(fmt REQUIRED)
endif () endif ()
set(SPDLOG_CFLAGS "${SPDLOG_CFLAGS} -DSPDLOG_FMT_EXTERNAL")
target_compile_definitions(spdlog PUBLIC SPDLOG_FMT_EXTERNAL) target_compile_definitions(spdlog PUBLIC SPDLOG_FMT_EXTERNAL)
target_link_libraries(spdlog PUBLIC fmt::fmt) target_link_libraries(spdlog PUBLIC fmt::fmt)
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_FMT_EXTERNAL) target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_FMT_EXTERNAL)
target_link_libraries(spdlog_header_only INTERFACE fmt::fmt) target_link_libraries(spdlog_header_only INTERFACE fmt::fmt)
set(PKG_CONFIG_REQUIRES fmt) # add dependecy to pkg-config
endif() endif()
if(SPDLOG_WCHAR_SUPPORT) if(SPDLOG_WCHAR_SUPPORT)
@ -204,11 +201,17 @@ if (SPDLOG_INSTALL)
endif() endif()
#--------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------
# Package and version files # Install pkg-config file
#--------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------
get_target_property(PKG_CONFIG_DEFINES spdlog INTERFACE_COMPILE_DEFINITIONS)
string(REPLACE ";" " -D" PKG_CONFIG_DEFINES "${PKG_CONFIG_DEFINES}")
string(CONCAT PKG_CONFIG_DEFINES "-D" "${PKG_CONFIG_DEFINES}")
configure_file("cmake/${PROJECT_NAME}.pc.in" "${pkg_config}" @ONLY) configure_file("cmake/${PROJECT_NAME}.pc.in" "${pkg_config}" @ONLY)
install(FILES "${pkg_config}" DESTINATION "${pkgconfig_install_dir}") install(FILES "${pkg_config}" DESTINATION "${pkgconfig_install_dir}")
#---------------------------------------------------------------------------------------
# Install CMake config files
#---------------------------------------------------------------------------------------
install(EXPORT spdlog install(EXPORT spdlog
DESTINATION ${export_dest_dir} DESTINATION ${export_dest_dir}
NAMESPACE spdlog:: NAMESPACE spdlog::
@ -216,6 +219,7 @@ if (SPDLOG_INSTALL)
include(CMakePackageConfigHelpers) include(CMakePackageConfigHelpers)
configure_file("${project_config_in}" "${project_config_out}" @ONLY) configure_file("${project_config_in}" "${project_config_out}" @ONLY)
write_basic_package_version_file("${version_config_file}" COMPATIBILITY SameMajorVersion) write_basic_package_version_file("${version_config_file}" COMPATIBILITY SameMajorVersion)
install(FILES install(FILES
"${project_config_out}" "${project_config_out}"
@ -227,3 +231,4 @@ if (SPDLOG_INSTALL)
include(cmake/spdlogCPack.cmake) include(cmake/spdlogCPack.cmake)
endif () endif ()

@ -30,6 +30,8 @@ $ cmake .. && make -j
* Gentoo: `emerge dev-libs/spdlog` * Gentoo: `emerge dev-libs/spdlog`
* Arch Linux: `yaourt -S spdlog-git` * Arch Linux: `yaourt -S spdlog-git`
* vcpkg: `vcpkg install spdlog` * vcpkg: `vcpkg install spdlog`
* conan: `spdlog/[>=1.4.1]@bincrafters/stable`
## Features ## Features
* Very fast (see [benchmarks](#benchmarks) below). * Very fast (see [benchmarks](#benchmarks) below).

@ -7,5 +7,7 @@ Name: lib@PROJECT_NAME@
Description: Fast C++ logging library. Description: Fast C++ logging library.
URL: https://github.com/gabime/@PROJECT_NAME@ URL: https://github.com/gabime/@PROJECT_NAME@
Version: @SPDLOG_VERSION@ Version: @SPDLOG_VERSION@
CFlags: -I${includedir}/@SPDLOG_CFLAGS@ CFlags: -I${includedir} @PKG_CONFIG_DEFINES@
Libs: -L${libdir}/@PROJECT_NAME@ -l@PROJECT_NAME@ Libs: -L${libdir} -lspdlog -pthread
Requires: @PKG_CONFIG_REQUIRES@

@ -69,6 +69,11 @@ SPDLOG_INLINE bool logger::should_log(level::level_enum msg_level) const
return msg_level >= level_.load(std::memory_order_relaxed); return msg_level >= level_.load(std::memory_order_relaxed);
} }
SPDLOG_INLINE bool logger::should_backtrace() const
{
return tracer_.enabled();
}
SPDLOG_INLINE void logger::set_level(level::level_enum log_level) SPDLOG_INLINE void logger::set_level(level::level_enum log_level)
{ {
level_.store(log_level); level_.store(log_level);

@ -319,8 +319,12 @@ public:
#endif // _WIN32 #endif // _WIN32
#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT #endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT
// return true logging is enabled for the given level.
bool should_log(level::level_enum msg_level) const; bool should_log(level::level_enum msg_level) const;
// return true if backtrace logging is enabled.
bool should_backtrace() const;
void set_level(level::level_enum log_level); void set_level(level::level_enum log_level);
level::level_enum level() const; level::level_enum level() const;

@ -285,7 +285,10 @@ inline void critical(wstring_view_t fmt, const Args &... args)
// SPDLOG_LEVEL_OFF // SPDLOG_LEVEL_OFF
// //
#define SPDLOG_LOGGER_CALL(logger, level, ...) logger->log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__) #define SPDLOG_LOGGER_CALL(logger, level, ...) do {\
if(logger->should_log(level) || logger->should_backtrace()) \
logger->log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__);\
} while(0)
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
#define SPDLOG_LOGGER_TRACE(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::trace, __VA_ARGS__) #define SPDLOG_LOGGER_TRACE(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::trace, __VA_ARGS__)

@ -5,6 +5,6 @@
#define SPDLOG_VER_MAJOR 1 #define SPDLOG_VER_MAJOR 1
#define SPDLOG_VER_MINOR 4 #define SPDLOG_VER_MINOR 4
#define SPDLOG_VER_PATCH 1 #define SPDLOG_VER_PATCH 2
#define SPDLOG_VERSION (SPDLOG_VER_MAJOR * 10000 + SPDLOG_VER_MINOR * 100 + SPDLOG_VER_PATCH) #define SPDLOG_VERSION (SPDLOG_VER_MAJOR * 10000 + SPDLOG_VER_MINOR * 100 + SPDLOG_VER_PATCH)

@ -39,3 +39,13 @@ TEST_CASE("disable param evaluation", "[macros]")
{ {
SPDLOG_TRACE("Test message {}", throw std::runtime_error("Should not be evaluated")); SPDLOG_TRACE("Test message {}", throw std::runtime_error("Should not be evaluated"));
} }
// ensure that even if right macro level is on- don't eavluate if the logger's level is not high enough
TEST_CASE("disable param evaluation2", "[macros]")
{
auto logger = std::make_shared<spdlog::logger>("test-macro");
logger->set_level(spdlog::level::off);
int x = 0;
SPDLOG_LOGGER_DEBUG(logger, "Test message {}", ++x);
REQUIRE(x == 0);
}

Loading…
Cancel
Save