mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-25 18:11:27 +02:00
log: clean up LogPrintStr_ and Reset, prefix all logs with "[*]" when there are suppressions
In LogPrintStr_: - remove an unnecessary BCLog since we are in the BCLog namespace. - remove an unnecessary \n when rate limiting is triggered since FormatLogStrInPlace will add it. - move the ratelimit bool into an else if block. - prefix all log lines with [*] when suppressions exist. Previously this was only done if should_ratelimit was true. In Reset: - remove an unnecessary \n since FormatLogStrInPlace will add it. - Change Level::Info to Level::Warning.
This commit is contained in:
@@ -455,24 +455,26 @@ void BCLog::Logger::LogPrintStr_(std::string_view str, std::source_location&& so
|
|||||||
bool ratelimit{false};
|
bool ratelimit{false};
|
||||||
if (should_ratelimit && m_limiter) {
|
if (should_ratelimit && m_limiter) {
|
||||||
auto status{m_limiter->Consume(source_loc, str_prefixed)};
|
auto status{m_limiter->Consume(source_loc, str_prefixed)};
|
||||||
if (status == BCLog::LogRateLimiter::Status::NEWLY_SUPPRESSED) {
|
if (status == LogRateLimiter::Status::NEWLY_SUPPRESSED) {
|
||||||
// NOLINTNEXTLINE(misc-no-recursion)
|
// NOLINTNEXTLINE(misc-no-recursion)
|
||||||
LogPrintStr_(strprintf(
|
LogPrintStr_(strprintf(
|
||||||
"Excessive logging detected from %s:%d (%s): >%d bytes logged during "
|
"Excessive logging detected from %s:%d (%s): >%d bytes logged during "
|
||||||
"the last time window of %is. Suppressing logging to disk from this "
|
"the last time window of %is. Suppressing logging to disk from this "
|
||||||
"source location until time window resets. Console logging "
|
"source location until time window resets. Console logging "
|
||||||
"unaffected. Last log entry.\n",
|
"unaffected. Last log entry.",
|
||||||
source_loc.file_name(), source_loc.line(), source_loc.function_name(),
|
source_loc.file_name(), source_loc.line(), source_loc.function_name(),
|
||||||
m_limiter->m_max_bytes,
|
m_limiter->m_max_bytes,
|
||||||
Ticks<std::chrono::seconds>(m_limiter->m_reset_window)),
|
Ticks<std::chrono::seconds>(m_limiter->m_reset_window)),
|
||||||
std::source_location::current(), LogFlags::ALL, Level::Warning, /*should_ratelimit=*/false); // with should_ratelimit=false, this cannot lead to infinite recursion
|
std::source_location::current(), LogFlags::ALL, Level::Warning, /*should_ratelimit=*/false); // with should_ratelimit=false, this cannot lead to infinite recursion
|
||||||
|
} else if (status == LogRateLimiter::Status::STILL_SUPPRESSED) {
|
||||||
|
ratelimit = true;
|
||||||
}
|
}
|
||||||
ratelimit = status == BCLog::LogRateLimiter::Status::STILL_SUPPRESSED;
|
}
|
||||||
// To avoid confusion caused by dropped log messages when debugging an issue,
|
|
||||||
// we prefix log lines with "[*]" when there are any suppressed source locations.
|
// To avoid confusion caused by dropped log messages when debugging an issue,
|
||||||
if (m_limiter->SuppressionsActive()) {
|
// we prefix log lines with "[*]" when there are any suppressed source locations.
|
||||||
str_prefixed.insert(0, "[*] ");
|
if (m_limiter && m_limiter->SuppressionsActive()) {
|
||||||
}
|
str_prefixed.insert(0, "[*] ");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_print_to_console) {
|
if (m_print_to_console) {
|
||||||
@@ -552,8 +554,8 @@ void BCLog::LogRateLimiter::Reset()
|
|||||||
for (const auto& [source_loc, stats] : source_locations) {
|
for (const auto& [source_loc, stats] : source_locations) {
|
||||||
if (stats.m_dropped_bytes == 0) continue;
|
if (stats.m_dropped_bytes == 0) continue;
|
||||||
LogPrintLevel_(
|
LogPrintLevel_(
|
||||||
LogFlags::ALL, Level::Info, /*should_ratelimit=*/false,
|
LogFlags::ALL, Level::Warning, /*should_ratelimit=*/false,
|
||||||
"Restarting logging from %s:%d (%s): %d bytes were dropped during the last %ss.\n",
|
"Restarting logging from %s:%d (%s): %d bytes were dropped during the last %ss.",
|
||||||
source_loc.file_name(), source_loc.line(), source_loc.function_name(),
|
source_loc.file_name(), source_loc.line(), source_loc.function_name(),
|
||||||
stats.m_dropped_bytes, Ticks<std::chrono::seconds>(m_reset_window));
|
stats.m_dropped_bytes, Ticks<std::chrono::seconds>(m_reset_window));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user