diff options
Diffstat (limited to 'src/zenutil/include')
| -rw-r--r-- | src/zenutil/include/zenutil/logging/fullformatter.h | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/zenutil/include/zenutil/logging/fullformatter.h b/src/zenutil/include/zenutil/logging/fullformatter.h index 146fea7a0..d4a04d3e5 100644 --- a/src/zenutil/include/zenutil/logging/fullformatter.h +++ b/src/zenutil/include/zenutil/logging/fullformatter.h @@ -42,6 +42,7 @@ public: TimestampSeconds = std::chrono::duration_cast<std::chrono::seconds>(msg.time.time_since_epoch()); if (TimestampSeconds != m_LastLogSecs) { + RwLock::ExclusiveLockScope _(m_TimestampLock); m_LastLogSecs = TimestampSeconds; m_CachedLocalTm = spdlog::details::os::localtime(spdlog::log_clock::to_time_t(msg.time)); @@ -66,10 +67,10 @@ public: auto ElapsedTime = msg.time - m_Epoch; TimestampSeconds = std::chrono::duration_cast<std::chrono::seconds>(ElapsedTime); - // cache the date/time part for the next second. - - if (m_CacheTimestamp != TimestampSeconds || m_CachedDatetime.size() == 0) + if (m_CacheTimestamp.load() != TimestampSeconds) { + RwLock::ExclusiveLockScope _(m_TimestampLock); + m_CacheTimestamp = TimestampSeconds; int Count = int(TimestampSeconds.count()); @@ -90,7 +91,10 @@ public: } } - OutBuffer.append(m_CachedDatetime.begin(), m_CachedDatetime.end()); + { + RwLock::SharedLockScope _(m_TimestampLock); + OutBuffer.append(m_CachedDatetime.begin(), m_CachedDatetime.end()); + } auto millis = spdlog::details::fmt_helper::time_fraction<std::chrono::milliseconds>(msg.time); spdlog::details::fmt_helper::pad3(static_cast<uint32_t>(millis.count()), OutBuffer); @@ -180,11 +184,12 @@ private: std::chrono::time_point<std::chrono::system_clock> m_Epoch; std::tm m_CachedLocalTm; std::chrono::seconds m_LastLogSecs; - std::chrono::seconds m_CacheTimestamp{0}; + std::atomic<std::chrono::seconds> m_CacheTimestamp; spdlog::memory_buf_t m_CachedDatetime; std::string m_LogId; std::string m_LinePrefix; bool m_UseFullDate = true; + RwLock m_TimestampLock; }; } // namespace zen::logging |