mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-15 09:17:57 +00:00
Compare commits
6 Commits
d67efb2cab
...
3f30000088
Author | SHA1 | Date | |
---|---|---|---|
|
3f30000088 | ||
|
e6ce39f76e | ||
|
10116b7717 | ||
|
18edb8bd63 | ||
|
dae1aeb1f7 | ||
|
57085c892f |
@ -63,19 +63,25 @@ option(SPDLOG_SANITIZE_ADDRESS "Enable address sanitizer in tests" OFF)
|
||||
# install options
|
||||
option(SPDLOG_INSTALL "Generate the install target" ${SPDLOG_MASTER_PROJECT})
|
||||
option(SPDLOG_FMT_EXTERNAL "Use external fmt library instead of bundled" OFF)
|
||||
|
||||
if(WIN32)
|
||||
option(SPDLOG_WCHAR_SUPPORT "Support wchar api" OFF)
|
||||
option(SPDLOG_WCHAR_FILENAMES "Support wchar filenames" OFF)
|
||||
endif()
|
||||
|
||||
option(SPDLOG_NO_EXCEPTIONS "Compile with -fno-exceptions. Call abort() on any spdlog exceptions" OFF)
|
||||
|
||||
|
||||
# misc tweakme options
|
||||
if(WIN32)
|
||||
option(SPDLOG_WCHAR_SUPPORT "Support wchar api" OFF)
|
||||
option(SPDLOG_WCHAR_FILENAMES "Support wchar filenames" OFF)
|
||||
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)
|
||||
endif()
|
||||
|
||||
option(SPDLOG_PREVENT_CHILD_FD "Prevent from child processes to inherit log file descriptors" OFF)
|
||||
option(SPDLOG_NO_THREAD_ID "prevent spdlog from querying the thread id on each log call if thread id is not needed" OFF)
|
||||
option(SPDLOG_NO_TLS "prevent spdlog from using thread local storage" OFF)
|
||||
option(SPDLOG_NO_ATOMIC_LEVELS "prevent spdlog from using of std::atomic log levels (use only if your code never modifies log levels concurrently" OFF)
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
message(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
# Static/Shared library (shared not supported in windows yet)
|
||||
#---------------------------------------------------------------------------------------
|
||||
@ -140,6 +146,9 @@ if(SPDLOG_FMT_EXTERNAL)
|
||||
set(PKG_CONFIG_REQUIRES fmt) # add dependency to pkg-config
|
||||
endif()
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
# Misc definitions according to tweak options
|
||||
#---------------------------------------------------------------------------------------
|
||||
if(SPDLOG_WCHAR_SUPPORT)
|
||||
target_compile_definitions(spdlog PUBLIC SPDLOG_WCHAR_TO_UTF8_SUPPORT)
|
||||
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_WCHAR_TO_UTF8_SUPPORT)
|
||||
@ -160,6 +169,31 @@ if(SPDLOG_WCHAR_SUPPORT)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(SPDLOG_CLOCK_COARSE)
|
||||
target_compile_definitions(spdlog PRIVATE SPDLOG_CLOCK_COARSE)
|
||||
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_CLOCK_COARSE)
|
||||
endif()
|
||||
|
||||
if(SPDLOG_PREVENT_CHILD_FD)
|
||||
target_compile_definitions(spdlog PRIVATE SPDLOG_PREVENT_CHILD_FD)
|
||||
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_PREVENT_CHILD_FD)
|
||||
endif()
|
||||
|
||||
if(SPDLOG_NO_THREAD_ID)
|
||||
target_compile_definitions(spdlog PRIVATE SPDLOG_NO_THREAD_ID)
|
||||
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_NO_THREAD_ID)
|
||||
endif()
|
||||
|
||||
if(SPDLOG_NO_TLS)
|
||||
target_compile_definitions(spdlog PRIVATE SPDLOG_NO_TLS)
|
||||
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_NO_TLS)
|
||||
endif()
|
||||
|
||||
if(SPDLOG_NO_ATOMIC_LEVELS)
|
||||
target_compile_definitions(spdlog PUBLIC SPDLOG_NO_ATOMIC_LEVELS)
|
||||
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_NO_ATOMIC_LEVELS)
|
||||
endif()
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
# Build binaries
|
||||
|
@ -15,10 +15,7 @@ namespace details {
|
||||
SPDLOG_INLINE log_msg::log_msg(spdlog::source_loc loc, string_view_t logger_name, spdlog::level::level_enum lvl, spdlog::string_view_t msg)
|
||||
: logger_name(logger_name)
|
||||
, level(lvl)
|
||||
#ifndef SPDLOG_NO_DATETIME
|
||||
, time(os::now())
|
||||
#endif
|
||||
|
||||
#ifndef SPDLOG_NO_THREAD_ID
|
||||
, thread_id(os::thread_id())
|
||||
#endif
|
||||
|
@ -126,15 +126,13 @@ SPDLOG_INLINE std::tm gmtime() SPDLOG_NOEXCEPT
|
||||
return gmtime(now_t);
|
||||
}
|
||||
|
||||
#ifdef SPDLOG_PREVENT_CHILD_FD
|
||||
SPDLOG_INLINE void prevent_child_fd(FILE *f)
|
||||
{
|
||||
|
||||
#ifdef _WIN32
|
||||
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM)
|
||||
auto file_handle = reinterpret_cast<HANDLE>(_get_osfhandle(::_fileno(f)));
|
||||
if (!::SetHandleInformation(file_handle, HANDLE_FLAG_INHERIT, 0))
|
||||
SPDLOG_THROW(spdlog_ex("SetHandleInformation failed", errno));
|
||||
#endif
|
||||
#else
|
||||
auto fd = ::fileno(f);
|
||||
if (::fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
|
||||
@ -143,6 +141,7 @@ SPDLOG_INLINE void prevent_child_fd(FILE *f)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif // SPDLOG_PREVENT_CHILD_FD
|
||||
|
||||
// fopen_s on non windows for writing
|
||||
SPDLOG_INLINE bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode)
|
||||
@ -158,6 +157,7 @@ SPDLOG_INLINE bool fopen_s(FILE **fp, const filename_t &filename, const filename
|
||||
#endif
|
||||
|
||||
#ifdef SPDLOG_PREVENT_CHILD_FD
|
||||
// prevent child processes from inheriting log file descriptors
|
||||
if (*fp != nullptr)
|
||||
{
|
||||
prevent_child_fd(*fp);
|
||||
|
@ -38,7 +38,9 @@ static const char folder_sep = '\\';
|
||||
SPDLOG_CONSTEXPR static const char folder_sep = '/';
|
||||
#endif
|
||||
|
||||
#ifdef SPDLOG_PREVENT_CHILD_FD
|
||||
void prevent_child_fd(FILE *f);
|
||||
#endif
|
||||
|
||||
// fopen_s on non windows for writing
|
||||
bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode);
|
||||
|
@ -904,8 +904,6 @@ public:
|
||||
using std::chrono::milliseconds;
|
||||
using std::chrono::seconds;
|
||||
|
||||
#ifndef SPDLOG_NO_DATETIME
|
||||
|
||||
// cache the date/time part for the next second.
|
||||
auto duration = msg.time.time_since_epoch();
|
||||
auto secs = duration_cast<seconds>(duration);
|
||||
@ -941,10 +939,6 @@ public:
|
||||
dest.push_back(']');
|
||||
dest.push_back(' ');
|
||||
|
||||
#else // no datetime needed
|
||||
(void)tm_time;
|
||||
#endif
|
||||
|
||||
#ifndef SPDLOG_NO_NAME
|
||||
if (msg.logger_name.size() > 0)
|
||||
{
|
||||
@ -1014,14 +1008,13 @@ SPDLOG_INLINE std::unique_ptr<formatter> pattern_formatter::clone() const
|
||||
|
||||
SPDLOG_INLINE void pattern_formatter::format(const details::log_msg &msg, memory_buf_t &dest)
|
||||
{
|
||||
#ifndef SPDLOG_NO_DATETIME
|
||||
auto secs = std::chrono::duration_cast<std::chrono::seconds>(msg.time.time_since_epoch());
|
||||
if (secs != last_log_secs_)
|
||||
{
|
||||
cached_tm_ = get_time_(msg);
|
||||
last_log_secs_ = secs;
|
||||
}
|
||||
#endif
|
||||
|
||||
for (auto &f : formatters_)
|
||||
{
|
||||
f->format(msg, cached_tm_, dest);
|
||||
|
@ -78,12 +78,7 @@ public:
|
||||
protected:
|
||||
void sink_it_(const details::log_msg &msg) override
|
||||
{
|
||||
#ifdef SPDLOG_NO_DATETIME
|
||||
auto time = log_clock::now();
|
||||
#else
|
||||
auto time = msg.time;
|
||||
#endif
|
||||
|
||||
bool should_rotate = time >= rotation_tp_;
|
||||
if (should_rotate)
|
||||
{
|
||||
|
@ -33,10 +33,6 @@
|
||||
// [2019-06-25 17:50:56.512] [logger] [info] Skipped 3 duplicate messages..
|
||||
// [2019-06-25 17:50:56.512] [logger] [info] Different Hello
|
||||
|
||||
#ifdef SPDLOG_NO_DATETIME
|
||||
#error "spdlog::sinks::dup_filter_sink: cannot work when SPDLOG_NO_DATETIME is defined"
|
||||
#endif
|
||||
|
||||
namespace spdlog {
|
||||
namespace sinks {
|
||||
template<typename Mutex>
|
||||
|
@ -19,19 +19,6 @@
|
||||
// #define SPDLOG_CLOCK_COARSE
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Uncomment if date/time logging is not needed and never appear in the log
|
||||
// pattern.
|
||||
// This will prevent spdlog from querying the clock on each log call.
|
||||
//
|
||||
// WARNING: If the log pattern contains any date/time while this flag is on, the
|
||||
// result is undefined.
|
||||
// You must set new pattern(spdlog::set_pattern(..") without any
|
||||
// date/time in it
|
||||
//
|
||||
// #define SPDLOG_NO_DATETIME
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Uncomment if thread id logging is not needed (i.e. no %t in the log pattern).
|
||||
// This will prevent spdlog from querying the thread id on each log call.
|
||||
|
@ -22,9 +22,9 @@ set(SPDLOG_UTESTS_SOURCES
|
||||
main.cpp
|
||||
test_mpmc_q.cpp
|
||||
test_sink.h
|
||||
test_dup_filter.cpp
|
||||
test_fmt_helper.cpp
|
||||
test_stdout_api.cpp
|
||||
test_dup_filter.cpp
|
||||
test_backtrace.cpp
|
||||
test_create_dir.cpp)
|
||||
|
||||
@ -36,6 +36,7 @@ if(systemd_FOUND)
|
||||
list(APPEND SPDLOG_UTESTS_SOURCES test_systemd.cpp)
|
||||
endif()
|
||||
|
||||
|
||||
enable_testing()
|
||||
|
||||
function(spdlog_prepare_test test_target spdlog_lib)
|
||||
|
Loading…
Reference in New Issue
Block a user