From 372183555be6538b32db4984eccebf85bcb73468 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 30 Aug 2019 14:46:38 +0700 Subject: [PATCH] #1141 Fixed log in background mode. --- src/base/io/log/Log.cpp | 9 +++++++-- src/base/io/log/Log.h | 1 + src/base/kernel/Base.cpp | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/base/io/log/Log.cpp b/src/base/io/log/Log.cpp index 8d56f7c95..250bc3c4c 100644 --- a/src/base/io/log/Log.cpp +++ b/src/base/io/log/Log.cpp @@ -91,6 +91,10 @@ public: std::lock_guard lock(m_mutex); + if (Log::background && m_backends.empty()) { + return; + } + timestamp(level, size, offset); color(level, size); @@ -190,8 +194,9 @@ private: }; -bool Log::colors = true; -LogPrivate *Log::d = new LogPrivate(); +bool Log::background = false; +bool Log::colors = true; +LogPrivate *Log::d = new LogPrivate(); } /* namespace xmrig */ diff --git a/src/base/io/log/Log.h b/src/base/io/log/Log.h index d8bcb44a7..3517b61d4 100644 --- a/src/base/io/log/Log.h +++ b/src/base/io/log/Log.h @@ -54,6 +54,7 @@ public: static void print(const char *fmt, ...); static void print(Level level, const char *fmt, ...); + static bool background; static bool colors; private: diff --git a/src/base/kernel/Base.cpp b/src/base/kernel/Base.cpp index 152f6bccd..3740655df 100644 --- a/src/base/kernel/Base.cpp +++ b/src/base/kernel/Base.cpp @@ -184,7 +184,10 @@ int xmrig::Base::init() Platform::setProcessPriority(config()->cpu().priority()); # endif - if (!config()->isBackground()) { + if (config()->isBackground()) { + Log::background = true; + } + else { Log::add(new ConsoleLog()); }