MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / LogPrint_

Method LogPrint_

src/logging.cpp:441–516  ·  view source on GitHub ↗

NOLINTNEXTLINE(misc-no-recursion)

Source from the content-addressed store, hash-verified

439
440// NOLINTNEXTLINE(misc-no-recursion)
441void BCLog::Logger::LogPrint_(util::log::Entry entry)
442{
443 if (m_buffering) {
444 {
445 m_cur_buffer_memusage += MemUsage(entry);
446 m_msgs_before_open.push_back(std::move(entry));
447 }
448
449 while (m_cur_buffer_memusage > m_max_buffer_memusage) {
450 if (m_msgs_before_open.empty()) {
451 m_cur_buffer_memusage = 0;
452 break;
453 }
454 m_cur_buffer_memusage -= MemUsage(m_msgs_before_open.front());
455 m_msgs_before_open.pop_front();
456 ++m_buffer_lines_discarded;
457 }
458
459 return;
460 }
461
462 std::string str_prefixed{Format(entry)};
463 bool ratelimit{false};
464 if (entry.should_ratelimit && m_limiter) {
465 auto status{m_limiter->Consume(entry.source_loc, str_prefixed)};
466 if (status == LogRateLimiter::Status::NEWLY_SUPPRESSED) {
467 // NOLINTNEXTLINE(misc-no-recursion)
468 LogPrint_({
469 .category = LogFlags::ALL,
470 .level = Level::Warning,
471 .should_ratelimit = false, // with should_ratelimit=false, this cannot lead to infinite recursion
472 .source_loc = SourceLocation{__func__},
473 .message = strprintf(
474 "Excessive logging detected from %s:%d (%s): >%d bytes logged during "
475 "the last time window of %is. Suppressing logging to disk from this "
476 "source location until time window resets. Console logging "
477 "unaffected. Last log entry.",
478 entry.source_loc.file_name(), entry.source_loc.line(), entry.source_loc.function_name_short(),
479 m_limiter->m_max_bytes,
480 Ticks<std::chrono::seconds>(m_limiter->m_reset_window)),
481 });
482 } else if (status == LogRateLimiter::Status::STILL_SUPPRESSED) {
483 ratelimit = true;
484 }
485 }
486
487 // To avoid confusion caused by dropped log messages when debugging an issue,
488 // we prefix log lines with "[*]" when there are any suppressed source locations.
489 if (m_limiter && m_limiter->SuppressionsActive()) {
490 str_prefixed.insert(0, "[*] ");
491 }
492
493 if (m_print_to_console) {
494 // print to console
495 fwrite(str_prefixed.data(), 1, str_prefixed.size(), stdout);
496 fflush(stdout);
497 }
498 for (const auto& cb : m_print_callbacks) {

Callers

nothing calls this directly

Calls 15

MemUsageFunction · 0.85
fopenFunction · 0.85
FileWriteStrFunction · 0.85
ConsumeMethod · 0.80
file_nameMethod · 0.80
lineMethod · 0.80
function_name_shortMethod · 0.80
SuppressionsActiveMethod · 0.80
FormatEnum · 0.70
push_backMethod · 0.45
emptyMethod · 0.45
frontMethod · 0.45

Tested by

no test coverage detected