Bitcoin ABC  0.28.12
P2P Digital Currency
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

 ~Logger ()
 
void LogPrintStr (const std::string &str, const std::string &logging_function, const std::string &source_file, const int source_line)
 Send a string to the log output. More...
 
bool Enabled () const
 Returns whether logs will be written to any output. More...
 
std::list< std::function< void(const std::string &)> >::iterator PushBackCallback (std::function< void(const std::string &)> fun)
 Connect a slot to the print signal and return the connection. More...
 
void DeleteCallback (std::list< std::function< void(const std::string &)>>::iterator it)
 Delete a connection. More...
 
bool StartLogging ()
 Start logging (and flush all buffered messages) More...
 
void DisconnectTestLogger ()
 Only for testing. More...
 
void ShrinkDebugFile ()
 
uint32_t GetCategoryMask () const
 
void EnableCategory (LogFlags category)
 
bool EnableCategory (const std::string &str)
 
void DisableCategory (LogFlags category)
 
bool DisableCategory (const std::string &str)
 
bool WillLogCategory (LogFlags category) const
 Return true if log accepts specified category. More...
 
std::vector< LogCategoryLogCategoriesList () 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...
 
bool DefaultShrinkDebugFile () const
 Default for whether ShrinkDebugFile should be run. 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
 
fs::path m_file_path
 
std::atomic< bool > m_reopen_file {false}
 

Private Member Functions

FILE *m_fileout GUARDED_BY (m_cs)
 
std::list< std::string > m_msgs_before_open GUARDED_BY (m_cs)
 
bool m_buffering GUARDED_BY (m_cs)
 Buffer messages before logging can be started. More...
 
std::string LogTimestampStr (const std::string &str)
 
std::list< std::function< void(const std::string &)> > m_print_callbacks GUARDED_BY (m_cs)
 Slots that connect to the print signal. More...
 

Private Attributes

StdMutex m_cs
 
std::atomic_bool m_started_new_line {true}
 m_started_new_line is a state variable that will suppress printing of the timestamp when multiple calls are made that don't end in a newline. More...
 
std::atomic< uint32_t > m_categories {0}
 Log categories bitfield. More...
 

Detailed Description

Definition at line 73 of file logging.h.

Constructor & Destructor Documentation

◆ ~Logger()

BCLog::Logger::~Logger ( )

Definition at line 177 of file logging.cpp.

Member Function Documentation

◆ DefaultShrinkDebugFile()

bool BCLog::Logger::DefaultShrinkDebugFile ( ) const

Default for whether ShrinkDebugFile should be run.

Definition at line 362 of file logging.cpp.

Here is the caller graph for this function:

◆ DeleteCallback()

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

Delete a connection.

Definition at line 136 of file logging.h.

◆ DisableCategory() [1/2]

bool BCLog::Logger::DisableCategory ( const std::string &  str)

Definition at line 341 of file logging.cpp.

Here is the call graph for this function:

◆ DisableCategory() [2/2]

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

Definition at line 337 of file logging.cpp.

Here is the caller graph for this function:

◆ DisconnectTestLogger()

void BCLog::Logger::DisconnectTestLogger ( )

Only for testing.

Definition at line 89 of file logging.cpp.

◆ EnableCategory() [1/2]

bool BCLog::Logger::EnableCategory ( const std::string &  str)

Definition at line 328 of file logging.cpp.

Here is the call graph for this function:

◆ EnableCategory() [2/2]

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

Definition at line 324 of file logging.cpp.

Here is the caller graph for this function:

◆ Enabled()

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

Returns whether logs will be written to any output.

Definition at line 121 of file logging.h.

◆ GetCategoryMask()

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

Definition at line 149 of file logging.h.

Here is the caller graph for this function:

◆ GUARDED_BY() [1/4]

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

◆ GUARDED_BY() [2/4]

std::list<std::string> m_msgs_before_open BCLog::Logger::GUARDED_BY ( m_cs  )
private

◆ GUARDED_BY() [3/4]

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

Buffer messages before logging can be started.

◆ GUARDED_BY() [4/4]

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 99 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 155 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 162 of file logging.h.

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

◆ LogPrintStr()

void BCLog::Logger::LogPrintStr ( const std::string &  str,
const std::string &  logging_function,
const std::string &  source_file,
const int  source_line 
)

Send a string to the log output.

Definition at line 232 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 ( const std::string &  str)
private

Definition at line 183 of file logging.cpp.

Here is the call graph for this function:

◆ PushBackCallback()

std::list<std::function<void(const std::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 129 of file logging.h.

◆ ShrinkDebugFile()

void BCLog::Logger::ShrinkDebugFile ( )

Definition at line 285 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 44 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 ( LogFlags  category) const

Return true if log accepts specified category.

Definition at line 350 of file logging.cpp.

Here is the caller graph for this function:

Member Data Documentation

◆ m_categories

std::atomic<uint32_t> BCLog::Logger::m_categories {0}
private

Log categories bitfield.

Definition at line 93 of file logging.h.

◆ m_cs

StdMutex BCLog::Logger::m_cs
mutableprivate

Definition at line 77 of file logging.h.

◆ m_file_path

fs::path BCLog::Logger::m_file_path

Definition at line 110 of file logging.h.

◆ m_log_sourcelocations

bool BCLog::Logger::m_log_sourcelocations = DEFAULT_LOGSOURCELOCATIONS

Definition at line 108 of file logging.h.

◆ m_log_threadnames

bool BCLog::Logger::m_log_threadnames = DEFAULT_LOGTHREADNAMES

Definition at line 107 of file logging.h.

◆ m_log_time_micros

bool BCLog::Logger::m_log_time_micros = DEFAULT_LOGTIMEMICROS

Definition at line 106 of file logging.h.

◆ m_log_timestamps

bool BCLog::Logger::m_log_timestamps = DEFAULT_LOGTIMESTAMPS

Definition at line 105 of file logging.h.

◆ m_print_to_console

bool BCLog::Logger::m_print_to_console = false

Definition at line 102 of file logging.h.

◆ m_print_to_file

bool BCLog::Logger::m_print_to_file = false

Definition at line 103 of file logging.h.

◆ m_reopen_file

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

Definition at line 111 of file logging.h.

◆ m_started_new_line

std::atomic_bool BCLog::Logger::m_started_new_line {true}
private

m_started_new_line is a state variable that will suppress printing of the timestamp when multiple calls are made that don't end in a newline.

Definition at line 88 of file logging.h.


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