mirror of
https://github.com/xmrig/xmrig.git
synced 2025-01-03 17:40:13 +00:00
Less error prone log interface.
This commit is contained in:
parent
3cc8b19ca0
commit
5142a406b0
8 changed files with 27 additions and 19 deletions
|
@ -159,7 +159,7 @@ static void print_threads(Config *config)
|
|||
|
||||
static void print_commands(Config *)
|
||||
{
|
||||
if (Log::colors) {
|
||||
if (Log::isColors()) {
|
||||
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("COMMANDS ") MAGENTA_BG(WHITE_BOLD_S "h") WHITE_BOLD("ashrate, ")
|
||||
MAGENTA_BG(WHITE_BOLD_S "p") WHITE_BOLD("ause, ")
|
||||
MAGENTA_BG(WHITE_BOLD_S "r") WHITE_BOLD("esume"));
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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__)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -177,7 +177,7 @@ int xmrig::Base::init()
|
|||
Platform::init(config()->userAgent());
|
||||
|
||||
if (isBackground()) {
|
||||
Log::background = true;
|
||||
Log::setBackground(true);
|
||||
}
|
||||
else {
|
||||
Log::add(new ConsoleLog());
|
||||
|
|
|
@ -60,11 +60,11 @@ bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName)
|
|||
m_dryRun = reader.getBool("dry-run", m_dryRun);
|
||||
m_syslog = reader.getBool("syslog", m_syslog);
|
||||
m_watch = reader.getBool("watch", m_watch);
|
||||
Log::colors = reader.getBool("colors", Log::colors);
|
||||
m_logFile = reader.getString("log-file");
|
||||
m_userAgent = reader.getString("user-agent");
|
||||
m_version = reader.getUint("version");
|
||||
|
||||
Log::setColors(reader.getBool("colors", Log::isColors()));
|
||||
setPrintTime(reader.getUint("print-time", 60));
|
||||
setVerbose(reader.getValue("verbose"));
|
||||
|
||||
|
@ -134,9 +134,9 @@ void xmrig::BaseConfig::printVersions()
|
|||
void xmrig::BaseConfig::setVerbose(const rapidjson::Value &value)
|
||||
{
|
||||
if (value.IsBool()) {
|
||||
Log::verbose = value.GetBool() ? 1 : 0;
|
||||
Log::setVerbose(value.GetBool() ? 1 : 0);
|
||||
}
|
||||
else if (value.IsUint()) {
|
||||
Log::verbose = value.GetUint();
|
||||
Log::setVerbose(value.GetUint());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -218,7 +218,7 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const
|
|||
doc.AddMember("http", m_http.toJSON(doc), allocator);
|
||||
doc.AddMember("autosave", isAutoSave(), allocator);
|
||||
doc.AddMember("background", isBackground(), allocator);
|
||||
doc.AddMember("colors", Log::colors, allocator);
|
||||
doc.AddMember("colors", Log::isColors(), allocator);
|
||||
|
||||
# ifdef XMRIG_ALGO_RANDOMX
|
||||
doc.AddMember(StringRef(kRandomX), rx().toJSON(doc), allocator);
|
||||
|
@ -246,6 +246,6 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const
|
|||
doc.AddMember("retry-pause", m_pools.retryPause(), allocator);
|
||||
doc.AddMember("syslog", isSyslog(), allocator);
|
||||
doc.AddMember("user-agent", m_userAgent.toJSON(), allocator);
|
||||
doc.AddMember("verbose", Log::verbose, allocator);
|
||||
doc.AddMember("verbose", Log::verbose(), allocator);
|
||||
doc.AddMember("watch", m_watch, allocator);
|
||||
}
|
||||
|
|
|
@ -134,7 +134,7 @@ static HANDLE wrmsr_install_driver()
|
|||
SERVICE_STATUS status;
|
||||
const auto rc = QueryServiceStatus(hService, &status);
|
||||
|
||||
if (rc && Log::verbose) {
|
||||
if (rc && Log::isVerbose()) {
|
||||
DWORD dwBytesNeeded;
|
||||
|
||||
QueryServiceConfigA(hService, nullptr, 0, &dwBytesNeeded);
|
||||
|
|
Loading…
Reference in a new issue