mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
log, timer: allow not repeating log message on completion
This commit is contained in:
parent
113b863f07
commit
325da75a53
1 changed files with 15 additions and 6 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue