Skip to content

Commit 325da75

Browse files
committed
log, timer: allow not repeating log message on completion
1 parent 113b863 commit 325da75

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/logging/timer.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,24 @@ class Timer
2727
Timer(
2828
std::string prefix,
2929
std::string end_msg,
30-
BCLog::LogFlags log_category = BCLog::LogFlags::ALL) :
30+
BCLog::LogFlags log_category = BCLog::LogFlags::ALL,
31+
bool msg_on_completion = true) :
3132
m_prefix(std::move(prefix)),
3233
m_title(std::move(end_msg)),
33-
m_log_category(log_category)
34+
m_log_category(log_category),
35+
m_message_on_completion(msg_on_completion)
3436
{
3537
this->Log(strprintf("%s started", m_title));
3638
m_start_t = GetTime<std::chrono::microseconds>();
3739
}
3840

3941
~Timer()
4042
{
41-
this->Log(strprintf("%s completed", m_title));
43+
if (m_message_on_completion) {
44+
this->Log(strprintf("%s completed", m_title));
45+
} else {
46+
this->Log("completed");
47+
}
4248
}
4349

4450
void Log(const std::string& msg)
@@ -74,14 +80,17 @@ class Timer
7480
std::chrono::microseconds m_start_t{};
7581

7682
//! Log prefix; usually the name of the function this was created in.
77-
const std::string m_prefix{};
83+
const std::string m_prefix;
7884

7985
//! A descriptive message of what is being timed.
80-
const std::string m_title{};
86+
const std::string m_title;
8187

8288
//! Forwarded on to LogPrint if specified - has the effect of only
8389
//! outputting the timing log when a particular debug= category is specified.
84-
const BCLog::LogFlags m_log_category{};
90+
const BCLog::LogFlags m_log_category;
91+
92+
//! Whether to output the message again on completion.
93+
const bool m_message_on_completion;
8594
};
8695

8796
} // namespace BCLog

0 commit comments

Comments
 (0)