log, timer: allow not repeating log message on completion

pull/22872/head
Jon Atack 3 years ago
parent 113b863f07
commit 325da75a53
No known key found for this signature in database
GPG Key ID: 4F5721B3D0E3921D

@ -27,10 +27,12 @@ public:
Timer( Timer(
std::string prefix, std::string prefix,
std::string end_msg, 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_prefix(std::move(prefix)),
m_title(std::move(end_msg)), 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)); this->Log(strprintf("%s started", m_title));
m_start_t = GetTime<std::chrono::microseconds>(); m_start_t = GetTime<std::chrono::microseconds>();
@ -38,7 +40,11 @@ public:
~Timer() ~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) void Log(const std::string& msg)
@ -74,14 +80,17 @@ private:
std::chrono::microseconds m_start_t{}; std::chrono::microseconds m_start_t{};
//! Log prefix; usually the name of the function this was created in. //! 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. //! 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 //! Forwarded on to LogPrint if specified - has the effect of only
//! outputting the timing log when a particular debug= category is specified. //! 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 } // namespace BCLog

Loading…
Cancel
Save