util: Encapsulate logCategories within BCLog::Logger.

This commit is contained in:
Jim Posen
2018-04-11 13:02:01 -07:00
parent 6a6d764ca5
commit 3316a9ebb6
7 changed files with 55 additions and 28 deletions

View File

@@ -23,8 +23,6 @@ extern const char * const DEFAULT_DEBUGLOGFILE;
extern bool fLogIPs;
extern std::atomic<uint32_t> logCategories;
struct CLogCategoryActive
{
std::string category;
@@ -72,6 +70,9 @@ namespace BCLog {
*/
std::atomic_bool fStartedNewLine{true};
/** Log categories bitfield. */
std::atomic<uint32_t> logCategories{0};
std::string LogTimestampStr(const std::string& str);
public:
@@ -92,6 +93,13 @@ namespace BCLog {
fs::path GetDebugLogPath() const;
bool OpenDebugLog();
void ShrinkDebugFile();
uint32_t GetCategoryMask() const { return logCategories.load(); }
void EnableCategory(LogFlags flag);
void DisableCategory(LogFlags flag);
bool WillLogCategory(LogFlags category) const;
bool DefaultShrinkDebugFile() const;
};
} // namespace BCLog
@@ -99,9 +107,9 @@ namespace BCLog {
extern BCLog::Logger* const g_logger;
/** Return true if log accepts specified category */
static inline bool LogAcceptCategory(uint32_t category)
static inline bool LogAcceptCategory(BCLog::LogFlags category)
{
return (logCategories.load(std::memory_order_relaxed) & category) != 0;
return g_logger->WillLogCategory(category);
}
/** Returns a string with the log categories. */