Changeset View
Changeset View
Standalone View
Standalone View
src/logging.h
Show First 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | private: | ||||
/** | /** | ||||
* Log categories bitfield. | * Log categories bitfield. | ||||
*/ | */ | ||||
std::atomic<uint32_t> m_categories{0}; | std::atomic<uint32_t> m_categories{0}; | ||||
std::string LogTimestampStr(const std::string &str); | std::string LogTimestampStr(const std::string &str); | ||||
/** Slots that connect to the print signal */ | |||||
std::list<std::function<void(const std::string &)>> | |||||
m_print_callbacks /* GUARDED_BY(m_cs) */ {}; | |||||
public: | public: | ||||
bool m_print_to_console = false; | bool m_print_to_console = false; | ||||
bool m_print_to_file = false; | bool m_print_to_file = false; | ||||
bool m_log_timestamps = DEFAULT_LOGTIMESTAMPS; | bool m_log_timestamps = DEFAULT_LOGTIMESTAMPS; | ||||
bool m_log_time_micros = DEFAULT_LOGTIMEMICROS; | bool m_log_time_micros = DEFAULT_LOGTIMEMICROS; | ||||
bool m_log_threadnames = DEFAULT_LOGTHREADNAMES; | bool m_log_threadnames = DEFAULT_LOGTHREADNAMES; | ||||
fs::path m_file_path; | fs::path m_file_path; | ||||
std::atomic<bool> m_reopen_file{false}; | std::atomic<bool> m_reopen_file{false}; | ||||
~Logger(); | ~Logger(); | ||||
/** Send a string to the log output */ | /** Send a string to the log output */ | ||||
void LogPrintStr(const std::string &str); | void LogPrintStr(const std::string &str); | ||||
/** Returns whether logs will be written to any output */ | /** Returns whether logs will be written to any output */ | ||||
bool Enabled() const { | bool Enabled() const { | ||||
std::lock_guard<std::mutex> scoped_lock(m_cs); | std::lock_guard<std::mutex> scoped_lock(m_cs); | ||||
return m_buffering || m_print_to_console || m_print_to_file; | return m_buffering || m_print_to_console || m_print_to_file || | ||||
!m_print_callbacks.empty(); | |||||
} | |||||
/** Connect a slot to the print signal and return the connection */ | |||||
std::list<std::function<void(const std::string &)>>::iterator | |||||
PushBackCallback(std::function<void(const std::string &)> fun) { | |||||
std::lock_guard<std::mutex> scoped_lock(m_cs); | |||||
m_print_callbacks.push_back(std::move(fun)); | |||||
return --m_print_callbacks.end(); | |||||
} | |||||
/** Delete a connection */ | |||||
void DeleteCallback( | |||||
std::list<std::function<void(const std::string &)>>::iterator it) { | |||||
std::lock_guard<std::mutex> scoped_lock(m_cs); | |||||
m_print_callbacks.erase(it); | |||||
} | } | ||||
/** Start logging (and flush all buffered messages) */ | /** Start logging (and flush all buffered messages) */ | ||||
bool StartLogging(); | bool StartLogging(); | ||||
/** Only for testing */ | /** Only for testing */ | ||||
void DisconnectTestLogger(); | void DisconnectTestLogger(); | ||||
void ShrinkDebugFile(); | void ShrinkDebugFile(); | ||||
▲ Show 20 Lines • Show All 71 Lines • Show Last 20 Lines |