aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2024-11-18 20:25:01 +0100
committerGitHub Enterprise <[email protected]>2024-11-18 20:25:01 +0100
commit26b1b1ee2255632f16a762dfcb488ef3eff1660c (patch)
treed5156fd4350965617589c4034de12ff173e3dc3f /src
parentfix oplog chunk batch get (#221) (diff)
downloadzen-26b1b1ee2255632f16a762dfcb488ef3eff1660c.tar.xz
zen-26b1b1ee2255632f16a762dfcb488ef3eff1660c.zip
some fixes to timestamp caching in logging (#219)
* some fixes to timestamp caching in logging
Diffstat (limited to 'src')
-rw-r--r--src/zenutil/include/zenutil/logging/fullformatter.h4
-rw-r--r--src/zenutil/include/zenutil/logging/testformatter.h16
2 files changed, 13 insertions, 7 deletions
diff --git a/src/zenutil/include/zenutil/logging/fullformatter.h b/src/zenutil/include/zenutil/logging/fullformatter.h
index d4a04d3e5..64010ac1e 100644
--- a/src/zenutil/include/zenutil/logging/fullformatter.h
+++ b/src/zenutil/include/zenutil/logging/fullformatter.h
@@ -183,8 +183,8 @@ public:
private:
std::chrono::time_point<std::chrono::system_clock> m_Epoch;
std::tm m_CachedLocalTm;
- std::chrono::seconds m_LastLogSecs;
- std::atomic<std::chrono::seconds> m_CacheTimestamp;
+ std::chrono::seconds m_LastLogSecs{std::chrono::seconds(87654321)};
+ std::atomic<std::chrono::seconds> m_CacheTimestamp{std::chrono::seconds(87654321)};
spdlog::memory_buf_t m_CachedDatetime;
std::string m_LogId;
std::string m_LinePrefix;
diff --git a/src/zenutil/include/zenutil/logging/testformatter.h b/src/zenutil/include/zenutil/logging/testformatter.h
index 39fc44e75..bdeb287be 100644
--- a/src/zenutil/include/zenutil/logging/testformatter.h
+++ b/src/zenutil/include/zenutil/logging/testformatter.h
@@ -37,8 +37,10 @@ public:
auto duration = msg.time - m_Epoch;
auto secs = std::chrono::duration_cast<std::chrono::seconds>(duration);
- if (m_CacheTimestamp != secs || m_CachedDatetime.size() == 0)
+ if (m_CacheTimestamp != secs)
{
+ RwLock::ExclusiveLockScope _(m_TimestampLock);
+
m_CachedDatetime.clear();
m_CachedDatetime.push_back('[');
@@ -85,7 +87,10 @@ public:
m_CacheTimestamp = secs;
}
- dest.append(m_CachedDatetime.begin(), m_CachedDatetime.end());
+ {
+ RwLock::SharedLockScope _(m_TimestampLock);
+ dest.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()), dest);
@@ -137,10 +142,11 @@ public:
private:
std::chrono::time_point<std::chrono::system_clock> m_Epoch;
std::tm m_CachedTm;
- std::chrono::seconds m_LastLogSecs;
- std::chrono::seconds m_CacheTimestamp{0};
+ std::chrono::seconds m_LastLogSecs{std::chrono::seconds(87654321)};
+ std::chrono::seconds m_CacheTimestamp{std::chrono::seconds(87654321)};
spdlog::memory_buf_t m_CachedDatetime;
std::string m_LogId;
+ RwLock m_TimestampLock;
};
-} // namespace zen::logging \ No newline at end of file
+} // namespace zen::logging