Bitcoin Core 32.99.0
P2P Digital Currency
Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
BCLog::Logger Class Reference

#include <logging.h>

Collaboration diagram for BCLog::Logger:
[legend]

Public Member Functions

void LogPrint (util::log::Entry log_entry) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
 Send an entry to the log output. More...
 
bool Enabled () const EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
 Returns whether logs will be written to any output. More...
 
std::list< std::function< void(conststd::string &)> >::iterator PushBackCallback (std::function< void(const std::string &)> fun) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
 Connect a slot to the print signal and return the connection. More...
 
void DeleteCallback (std::list< std::function< void(const std::string &)> >::iterator it) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
 Delete a connection. More...
 
bool StartLogging () EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
 Start logging (and flush all buffered messages) More...
 
void DisconnectTestLogger () EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
 Only for testing. More...
 
void SetRateLimiting (std::shared_ptr< LogRateLimiter > limiter) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
 
void DisableLogging () EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
 Disable logging This offers a slight speedup and slightly smaller memory usage compared to leaving the logging system in its default state. More...
 
void ShrinkDebugFile () EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
 
std::unordered_map< LogFlags, Level > CategoryLevels () const EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
 
void SetCategoryLogLevel (const std::unordered_map< LogFlags, Level > &levels) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
 
void AddCategoryLogLevel (LogFlags category, Level level) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
 
bool SetCategoryLogLevel (std::string_view category_str, std::string_view level_str) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
 
Level LogLevel () const
 
void SetLogLevel (Level level)
 
bool SetLogLevel (std::string_view level)
 
CategoryMask GetCategoryMask () const
 
void EnableCategory (LogFlags flag)
 
bool EnableCategory (std::string_view str)
 
void DisableCategory (LogFlags flag)
 
bool DisableCategory (std::string_view str)
 
bool WillLogCategory (LogFlags category) const
 
bool WillLogCategoryLevel (LogFlags category, Level level) const EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
 
std::vector< LogCategory > LogCategoriesList () const
 Returns a vector of the log categories in alphabetical order. More...
 
std::string LogCategoriesString () const
 Returns a string with the log categories in alphabetical order. More...
 
std::string LogLevelsString () const
 Returns a string with all user-selectable log levels. More...
 
bool DefaultShrinkDebugFile () const
 

Static Public Member Functions

static std::string LogLevelToStr (BCLog::Level level)
 Returns the string representation of a log level. More...
 
static std::optional< BCLog::LogFlags > GetLogCategory (std::string_view str)
 Return log flag if str parses as a log category. More...
 

Public Attributes

bool m_print_to_console = false
 
bool m_print_to_file = false
 
bool m_log_timestamps = DEFAULT_LOGTIMESTAMPS
 
bool m_log_time_micros = DEFAULT_LOGTIMEMICROS
 
bool m_log_threadnames = DEFAULT_LOGTHREADNAMES
 
bool m_log_sourcelocations = DEFAULT_LOGSOURCELOCATIONS
 
bool m_always_print_category_level = DEFAULT_LOGLEVELALWAYS
 
fs::path m_file_path
 
std::atomic< bool > m_reopen_file {false}
 

Private Member Functions

FILE *m_fileout GUARDED_BY (m_cs)
 
std::list< util::log::Entry > m_msgs_before_open GUARDED_BY (m_cs)
 
bool m_buffering GUARDED_BY (m_cs)
 Buffer messages before logging can be started. More...
 
size_t m_max_buffer_memusage GUARDED_BY (m_cs)
 
size_t m_cur_buffer_memusage GUARDED_BY (m_cs)
 
size_t m_buffer_lines_discarded GUARDED_BY (m_cs)
 
std::shared_ptr< LogRateLimiter > m_limiter GUARDED_BY (m_cs)
 Manages the rate limiting of each log location. More...
 
std::unordered_map< LogFlags, Level > m_category_log_levels GUARDED_BY (m_cs)
 Category-specific log level. Overrides m_log_level. More...
 
std::string Format (const util::log::Entry &entry) const
 
std::string LogTimestampStr (SystemClock::time_point now, std::chrono::seconds mocktime) const
 
std::list< std::function< void(const std::string &)> > m_print_callbacks GUARDED_BY (m_cs)
 Slots that connect to the print signal. More...
 
void LogPrint_ (util::log::Entry log_entry) EXCLUSIVE_LOCKS_REQUIRED(m_cs)
 Send an entry to the log output (internal) More...
 
std::string GetLogPrefix (LogFlags category, Level level) const
 

Private Attributes

StdMutex m_cs
 
std::atomic< Level > m_log_level {DEFAULT_LOG_LEVEL}
 If there is no category-specific log level, all logs with a severity level lower than m_log_level will be ignored. More...
 
std::atomic< CategoryMask > m_categories {BCLog::NONE}
 Log categories bitfield. More...
 

Detailed Description

Definition at line 130 of file logging.h.

Member Function Documentation

◆ AddCategoryLogLevel()

void BCLog::Logger::AddCategoryLogLevel ( LogFlags  category,
Level  level 
)
inline

Definition at line 235 of file logging.h.

◆ CategoryLevels()

std::unordered_map< LogFlags, Level > BCLog::Logger::CategoryLevels ( ) const
inline

Definition at line 225 of file logging.h.

Here is the caller graph for this function:

◆ DefaultShrinkDebugFile()

bool BCLog::Logger::DefaultShrinkDebugFile ( ) const

Definition at line 175 of file logging.cpp.

◆ DeleteCallback()

void BCLog::Logger::DeleteCallback ( std::list< std::function< void(const std::string &)> >::iterator  it)
inline

Delete a connection.

Definition at line 199 of file logging.h.

Here is the caller graph for this function:

◆ DisableCategory() [1/2]

void BCLog::Logger::DisableCategory ( BCLog::LogFlags  flag)

Definition at line 143 of file logging.cpp.

Here is the caller graph for this function:

◆ DisableCategory() [2/2]

bool BCLog::Logger::DisableCategory ( std::string_view  str)

Definition at line 148 of file logging.cpp.

◆ DisableLogging()

void BCLog::Logger::DisableLogging ( )

Disable logging This offers a slight speedup and slightly smaller memory usage compared to leaving the logging system in its default state.

Should be used instead of StartLogging().

Definition at line 117 of file logging.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DisconnectTestLogger()

void BCLog::Logger::DisconnectTestLogger ( )

Only for testing.

Definition at line 104 of file logging.cpp.

Here is the caller graph for this function:

◆ EnableCategory() [1/2]

void BCLog::Logger::EnableCategory ( BCLog::LogFlags  flag)

Definition at line 129 of file logging.cpp.

Here is the caller graph for this function:

◆ EnableCategory() [2/2]

bool BCLog::Logger::EnableCategory ( std::string_view  str)

Definition at line 134 of file logging.cpp.

◆ Enabled()

bool BCLog::Logger::Enabled ( ) const
inline

Returns whether logs will be written to any output.

Definition at line 184 of file logging.h.

◆ Format()

std::string BCLog::Logger::Format ( const util::log::Entry &  entry) const
private

Definition at line 418 of file logging.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetCategoryMask()

CategoryMask BCLog::Logger::GetCategoryMask ( ) const
inline

Definition at line 246 of file logging.h.

◆ GetLogCategory()

std::optional< BCLog::LogFlags > BCLog::Logger::GetLogCategory ( std::string_view  str)
static

Return log flag if str parses as a log category.

Definition at line 228 of file logging.cpp.

Here is the caller graph for this function:

◆ GetLogPrefix()

std::string BCLog::Logger::GetLogPrefix ( BCLog::LogFlags  category,
BCLog::Level  level 
) const
private

Definition at line 354 of file logging.cpp.

Here is the call graph for this function:

◆ GUARDED_BY() [1/9]

FILE *m_fileout BCLog::Logger::GUARDED_BY ( m_cs  )
private

◆ GUARDED_BY() [2/9]

std::list< util::log::Entry > m_msgs_before_open BCLog::Logger::GUARDED_BY ( m_cs  )
private

◆ GUARDED_BY() [3/9]

bool m_buffering BCLog::Logger::GUARDED_BY ( m_cs  )
private

Buffer messages before logging can be started.

◆ GUARDED_BY() [4/9]

size_t m_max_buffer_memusage BCLog::Logger::GUARDED_BY ( m_cs  )
inlineprivate

Definition at line 138 of file logging.h.

◆ GUARDED_BY() [5/9]

size_t m_cur_buffer_memusage BCLog::Logger::GUARDED_BY ( m_cs  )
inlineprivate

Definition at line 139 of file logging.h.

◆ GUARDED_BY() [6/9]

size_t m_buffer_lines_discarded BCLog::Logger::GUARDED_BY ( m_cs  )
inlineprivate

Definition at line 140 of file logging.h.

◆ GUARDED_BY() [7/9]

std::shared_ptr< LogRateLimiter > m_limiter BCLog::Logger::GUARDED_BY ( m_cs  )
private

Manages the rate limiting of each log location.

◆ GUARDED_BY() [8/9]

std::unordered_map< LogFlags, Level > m_category_log_levels BCLog::Logger::GUARDED_BY ( m_cs  )
private

Category-specific log level. Overrides m_log_level.

◆ GUARDED_BY() [9/9]

std::list< std::function< void(const std::string &)> > m_print_callbacks BCLog::Logger::GUARDED_BY ( m_cs  )
inlineprivate

Slots that connect to the print signal.

Definition at line 160 of file logging.h.

◆ LogCategoriesList()

std::vector< LogCategory > BCLog::Logger::LogCategoriesList ( ) const

Returns a vector of the log categories in alphabetical order.

Definition at line 288 of file logging.cpp.

Here is the caller graph for this function:

◆ LogCategoriesString()

std::string BCLog::Logger::LogCategoriesString ( ) const
inline

Returns a string with the log categories in alphabetical order.

Definition at line 259 of file logging.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LogLevel()

Level BCLog::Logger::LogLevel ( ) const
inline

Definition at line 242 of file logging.h.

◆ LogLevelsString()

std::string BCLog::Logger::LogLevelsString ( ) const

Returns a string with all user-selectable log levels.

Definition at line 304 of file logging.cpp.

Here is the call graph for this function:

◆ LogLevelToStr()

std::string BCLog::Logger::LogLevelToStr ( BCLog::Level  level)
static

Returns the string representation of a log level.

Definition at line 244 of file logging.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LogPrint()

void BCLog::Logger::LogPrint ( util::log::Entry  log_entry)

Send an entry to the log output.

Definition at line 437 of file logging.cpp.

Here is the caller graph for this function:

◆ LogPrint_()

void BCLog::Logger::LogPrint_ ( util::log::Entry  log_entry)
private

Send an entry to the log output (internal)

Definition at line 444 of file logging.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LogTimestampStr()

std::string BCLog::Logger::LogTimestampStr ( SystemClock::time_point  now,
std::chrono::seconds  mocktime 
) const
private

Definition at line 310 of file logging.cpp.

Here is the call graph for this function:

◆ PushBackCallback()

std::list< std::function< void(conststd::string &)> >::iterator BCLog::Logger::PushBackCallback ( std::function< void(const std::string &)>  fun)
inline

Connect a slot to the print signal and return the connection.

Definition at line 191 of file logging.h.

Here is the caller graph for this function:

◆ SetCategoryLogLevel() [1/2]

void BCLog::Logger::SetCategoryLogLevel ( const std::unordered_map< LogFlags, Level > &  levels)
inline

Definition at line 230 of file logging.h.

Here is the caller graph for this function:

◆ SetCategoryLogLevel() [2/2]

bool BCLog::Logger::SetCategoryLogLevel ( std::string_view  category_str,
std::string_view  level_str 
)

Definition at line 608 of file logging.cpp.

Here is the call graph for this function:

◆ SetLogLevel() [1/2]

void BCLog::Logger::SetLogLevel ( Level  level)
inline

Definition at line 243 of file logging.h.

Here is the caller graph for this function:

◆ SetLogLevel() [2/2]

bool BCLog::Logger::SetLogLevel ( std::string_view  level)

Definition at line 600 of file logging.cpp.

Here is the call graph for this function:

◆ SetRateLimiting()

void BCLog::Logger::SetRateLimiting ( std::shared_ptr< LogRateLimiter >  limiter)
inline

Definition at line 210 of file logging.h.

Here is the caller graph for this function:

◆ ShrinkDebugFile()

void BCLog::Logger::ShrinkDebugFile ( )

Definition at line 521 of file logging.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ StartLogging()

bool BCLog::Logger::StartLogging ( )

Start logging (and flush all buffered messages)

Definition at line 55 of file logging.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WillLogCategory()

bool BCLog::Logger::WillLogCategory ( BCLog::LogFlags  category) const

Definition at line 157 of file logging.cpp.

◆ WillLogCategoryLevel()

bool BCLog::Logger::WillLogCategoryLevel ( BCLog::LogFlags  category,
BCLog::Level  level 
) const

Definition at line 162 of file logging.cpp.

Member Data Documentation

◆ m_always_print_category_level

bool BCLog::Logger::m_always_print_category_level = DEFAULT_LOGLEVELALWAYS

Definition at line 175 of file logging.h.

◆ m_categories

std::atomic<CategoryMask> BCLog::Logger::m_categories {BCLog::NONE}
private

Log categories bitfield.

Definition at line 153 of file logging.h.

◆ m_cs

StdMutex BCLog::Logger::m_cs
mutableprivate

Definition at line 133 of file logging.h.

◆ m_file_path

fs::path BCLog::Logger::m_file_path

Definition at line 177 of file logging.h.

◆ m_log_level

std::atomic<Level> BCLog::Logger::m_log_level {DEFAULT_LOG_LEVEL}
private

If there is no category-specific log level, all logs with a severity level lower than m_log_level will be ignored.

Definition at line 150 of file logging.h.

◆ m_log_sourcelocations

bool BCLog::Logger::m_log_sourcelocations = DEFAULT_LOGSOURCELOCATIONS

Definition at line 174 of file logging.h.

◆ m_log_threadnames

bool BCLog::Logger::m_log_threadnames = DEFAULT_LOGTHREADNAMES

Definition at line 173 of file logging.h.

◆ m_log_time_micros

bool BCLog::Logger::m_log_time_micros = DEFAULT_LOGTIMEMICROS

Definition at line 172 of file logging.h.

◆ m_log_timestamps

bool BCLog::Logger::m_log_timestamps = DEFAULT_LOGTIMESTAMPS

Definition at line 171 of file logging.h.

◆ m_print_to_console

bool BCLog::Logger::m_print_to_console = false

Definition at line 168 of file logging.h.

◆ m_print_to_file

bool BCLog::Logger::m_print_to_file = false

Definition at line 169 of file logging.h.

◆ m_reopen_file

std::atomic<bool> BCLog::Logger::m_reopen_file {false}

Definition at line 178 of file logging.h.


The documentation for this class was generated from the following files: