Less error prone log interface.

This commit is contained in:
XMRig 2019-12-18 02:20:31 +07:00
parent 3cc8b19ca0
commit 5142a406b0
No known key found for this signature in database
GPG key ID: 446A53638BE94409
8 changed files with 27 additions and 19 deletions

View file

@ -92,7 +92,7 @@ public:
std::lock_guard<std::mutex> lock(m_mutex);
if (Log::background && m_backends.empty()) {
if (Log::isBackground() && m_backends.empty()) {
return;
}
@ -195,10 +195,10 @@ private:
};
bool Log::background = false;
bool Log::colors = true;
bool Log::m_background = false;
bool Log::m_colors = true;
LogPrivate *Log::d = new LogPrivate();
uint32_t Log::verbose = 0;
uint32_t Log::m_verbose = 0;
} /* namespace xmrig */

View file

@ -57,11 +57,19 @@ public:
static void print(const char *fmt, ...);
static void print(Level level, const char *fmt, ...);
static bool background;
static bool colors;
static uint32_t verbose;
static inline bool isBackground() { return m_background; }
static inline bool isColors() { return m_colors; }
static inline bool isVerbose() { return m_verbose > 0; }
static inline uint32_t verbose() { return m_verbose; }
static inline void setBackground(bool background) { m_background = background; }
static inline void setColors(bool colors) { m_colors = colors; }
static inline void setVerbose(uint32_t verbose) { m_verbose = verbose; }
private:
static bool m_background;
static bool m_colors;
static uint32_t m_verbose;
static LogPrivate *d;
};
@ -130,7 +138,7 @@ private:
#define LOG_WARN(x, ...) xmrig::Log::print(xmrig::Log::WARNING, x, ##__VA_ARGS__)
#define LOG_NOTICE(x, ...) xmrig::Log::print(xmrig::Log::NOTICE, x, ##__VA_ARGS__)
#define LOG_INFO(x, ...) xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__)
#define LOG_VERBOSE(x, ...) if (xmrig::Log::verbose) { xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__); }
#define LOG_VERBOSE(x, ...) if (xmrig::Log::isVerbose()) { xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__); }
#ifdef APP_DEBUG
# define LOG_DEBUG(x, ...) xmrig::Log::print(xmrig::Log::DEBUG, x, ##__VA_ARGS__)

View file

@ -35,14 +35,14 @@
xmrig::ConsoleLog::ConsoleLog()
{
if (!isSupported()) {
Log::colors = false;
Log::setColors(false);
return;
}
m_tty = new uv_tty_t;
if (uv_tty_init(uv_default_loop(), m_tty, 1, 0) < 0) {
Log::colors = false;
Log::setColors(false);
return;
}
@ -71,7 +71,7 @@ xmrig::ConsoleLog::~ConsoleLog()
void xmrig::ConsoleLog::print(int, const char *line, size_t, size_t size, bool colors)
{
if (!m_tty || Log::colors != colors) {
if (!m_tty || Log::isColors() != colors) {
return;
}