diff options
author | Jon Atack <jon@atack.com> | 2021-09-11 20:32:58 +0200 |
---|---|---|
committer | Jon Atack <jon@atack.com> | 2021-10-05 17:27:54 +0200 |
commit | 325da75a5396f3161a6eade74b349105ed5722ab (patch) | |
tree | 8c9d6d508a617a62c298e87353346d75a87d563d /src/logging | |
parent | 113b863f0773999497f952daa6539a03a66a9de3 (diff) |
log, timer: allow not repeating log message on completion
Diffstat (limited to 'src/logging')
-rw-r--r-- | src/logging/timer.h | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/logging/timer.h b/src/logging/timer.h index 79627b1fe3..6725c71a95 100644 --- a/src/logging/timer.h +++ b/src/logging/timer.h @@ -27,10 +27,12 @@ public: Timer( std::string prefix, std::string end_msg, - BCLog::LogFlags log_category = BCLog::LogFlags::ALL) : + BCLog::LogFlags log_category = BCLog::LogFlags::ALL, + bool msg_on_completion = true) : m_prefix(std::move(prefix)), m_title(std::move(end_msg)), - m_log_category(log_category) + m_log_category(log_category), + m_message_on_completion(msg_on_completion) { this->Log(strprintf("%s started", m_title)); m_start_t = GetTime<std::chrono::microseconds>(); @@ -38,7 +40,11 @@ public: ~Timer() { - this->Log(strprintf("%s completed", m_title)); + if (m_message_on_completion) { + this->Log(strprintf("%s completed", m_title)); + } else { + this->Log("completed"); + } } void Log(const std::string& msg) @@ -74,14 +80,17 @@ private: std::chrono::microseconds m_start_t{}; //! Log prefix; usually the name of the function this was created in. - const std::string m_prefix{}; + const std::string m_prefix; //! A descriptive message of what is being timed. - const std::string m_title{}; + const std::string m_title; //! Forwarded on to LogPrint if specified - has the effect of only //! outputting the timing log when a particular debug= category is specified. - const BCLog::LogFlags m_log_category{}; + const BCLog::LogFlags m_log_category; + + //! Whether to output the message again on completion. + const bool m_message_on_completion; }; } // namespace BCLog |