Changeset View
Changeset View
Standalone View
Standalone View
src/logging.h
Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | enum LogFlags : uint32_t { | ||||
COINDB = (1 << 18), | COINDB = (1 << 18), | ||||
QT = (1 << 19), | QT = (1 << 19), | ||||
LEVELDB = (1 << 20), | LEVELDB = (1 << 20), | ||||
ALL = ~uint32_t(0), | ALL = ~uint32_t(0), | ||||
}; | }; | ||||
class Logger { | class Logger { | ||||
private: | private: | ||||
// Can not use Mutex from sync.h because in debug mode it would cause a | |||||
// deadlock when a potential deadlock was detected | |||||
mutable std::mutex m_cs; | |||||
// GUARDED_BY(m_cs) | |||||
deadalnix: Why not an actual annotation rather than a comment? | |||||
FabienAuthorUnsubmitted Done Inline ActionsMy understanding is that by not using the sync.h wrappers, the lock annotations (EXCLUSIVE_LOCK_FUNCTION(), UNLOCK_FUNCTION(), ...) are missing and GUARDED_BY() cannot be evaluated. Fabien: My understanding is that by not using the sync.h wrappers, the lock annotations… | |||||
FILE *m_fileout = nullptr; | FILE *m_fileout = nullptr; | ||||
std::mutex m_file_mutex; | // GUARDED_BY(m_cs) | ||||
std::list<std::string> m_msgs_before_open; | std::list<std::string> m_msgs_before_open; | ||||
//! Buffer messages before logging can be started. GUARDED_BY(m_cs) | |||||
bool m_buffering{true}; | |||||
/** | /** | ||||
* m_started_new_line is a state variable that will suppress printing of the | * 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. | * timestamp when multiple calls are made that don't end in a newline. | ||||
*/ | */ | ||||
std::atomic_bool m_started_new_line{true}; | std::atomic_bool m_started_new_line{true}; | ||||
/** | /** | ||||
Show All 15 Lines | public: | ||||
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 { return m_print_to_console || m_print_to_file; } | bool Enabled() const { | ||||
std::lock_guard<std::mutex> scoped_lock(m_cs); | |||||
return m_buffering || m_print_to_console || m_print_to_file; | |||||
} | |||||
/** Start logging (and flush all buffered messages) */ | |||||
bool StartLogging(); | |||||
bool OpenDebugLog(); | |||||
void ShrinkDebugFile(); | void ShrinkDebugFile(); | ||||
uint32_t GetCategoryMask() const { return m_categories.load(); } | uint32_t GetCategoryMask() const { return m_categories.load(); } | ||||
void EnableCategory(LogFlags category); | void EnableCategory(LogFlags category); | ||||
bool EnableCategory(const std::string &str); | bool EnableCategory(const std::string &str); | ||||
void DisableCategory(LogFlags category); | void DisableCategory(LogFlags category); | ||||
bool DisableCategory(const std::string &str); | bool DisableCategory(const std::string &str); | ||||
▲ Show 20 Lines • Show All 64 Lines • Show Last 20 Lines |
Why not an actual annotation rather than a comment?