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

@@ -26,9 +26,6 @@ BCLog::Logger* const g_logger = new BCLog::Logger();
bool fLogIPs = DEFAULT_LOGIPS;
/** Log categories bitfield. */
std::atomic<uint32_t> logCategories(0);
static int FileWriteStr(const std::string &str, FILE *fp)
{
return fwrite(str.data(), 1, str.size(), fp);
@@ -62,6 +59,26 @@ bool BCLog::Logger::OpenDebugLog()
return true;
}
void BCLog::Logger::EnableCategory(BCLog::LogFlags flag)
{
logCategories |= flag;
}
void BCLog::Logger::DisableCategory(BCLog::LogFlags flag)
{
logCategories &= ~flag;
}
bool BCLog::Logger::WillLogCategory(BCLog::LogFlags category) const
{
return (logCategories.load(std::memory_order_relaxed) & category) != 0;
}
bool BCLog::Logger::DefaultShrinkDebugFile() const
{
return logCategories == BCLog::NONE;
}
struct CLogCategoryDesc
{
uint32_t flag;