diff --git a/CMakeLists.txt b/CMakeLists.txt index 79f03392..bef4544e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,7 +76,6 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") endif() option(SPDLOG_PREVENT_CHILD_FD "Prevent from child processes to inherit log file descriptors" OFF) -option(SPDLOG_NO_DATETIME, "Prevent spdlog from querying the clock on each log call if no datetime is needed" OFF) option(SPDLOG_NO_THREAD_ID "prevent spdlog from querying the thread id on each log call if thread id is not needed" OFF) 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) @@ -180,12 +179,6 @@ if(SPDLOG_PREVENT_CHILD_FD) target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_PREVENT_CHILD_FD) endif() - -if(SPDLOG_NO_DATETIME) - target_compile_definitions(spdlog PUBLIC SPDLOG_NO_DATETIME) - target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_NO_DATETIME) -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) diff --git a/include/spdlog/details/log_msg-inl.h b/include/spdlog/details/log_msg-inl.h index cb130532..a47fe660 100644 --- a/include/spdlog/details/log_msg-inl.h +++ b/include/spdlog/details/log_msg-inl.h @@ -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 diff --git a/include/spdlog/details/pattern_formatter-inl.h b/include/spdlog/details/pattern_formatter-inl.h index 33a57a13..f97e2c2f 100644 --- a/include/spdlog/details/pattern_formatter-inl.h +++ b/include/spdlog/details/pattern_formatter-inl.h @@ -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(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 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(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); diff --git a/include/spdlog/sinks/daily_file_sink.h b/include/spdlog/sinks/daily_file_sink.h index 83b63e1a..d200480f 100644 --- a/include/spdlog/sinks/daily_file_sink.h +++ b/include/spdlog/sinks/daily_file_sink.h @@ -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) { diff --git a/include/spdlog/sinks/dup_filter_sink.h b/include/spdlog/sinks/dup_filter_sink.h index ab116a05..ab501387 100644 --- a/include/spdlog/sinks/dup_filter_sink.h +++ b/include/spdlog/sinks/dup_filter_sink.h @@ -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 diff --git a/include/spdlog/tweakme.h b/include/spdlog/tweakme.h index 2f3241b8..b67043e0 100644 --- a/include/spdlog/tweakme.h +++ b/include/spdlog/tweakme.h @@ -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. diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c3b346cc..14c03287 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -22,6 +22,7 @@ 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_backtrace.cpp @@ -35,12 +36,6 @@ if(systemd_FOUND) list(APPEND SPDLOG_UTESTS_SOURCES test_systemd.cpp) endif() -if(NOT SPDLOG_NO_DATETIME) - list(APPEND SPDLOG_UTESTS_SOURCES test_dup_filter.cpp) -endif() - - - enable_testing()