From ced25c3fa0dee1b239d86686875f9234d8b0395b Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 26 Mar 2019 19:56:35 +0700 Subject: [PATCH] Log subsystem rewritten, to handle both color and not color logs simultaneously and overall simplicity. --- CMakeLists.txt | 14 - src/App.cpp | 8 +- src/Summary.cpp | 24 +- src/base/base.cmake | 16 ++ src/base/io/log/Log.cpp | 245 ++++++++++++++++++ src/base/io/log/Log.h | 129 +++++++++ .../io/log/backends}/ConsoleLog.cpp | 73 ++---- .../log => base/io/log/backends}/ConsoleLog.h | 13 +- .../log => base/io/log/backends}/FileLog.cpp | 55 +--- .../log => base/io/log/backends}/FileLog.h | 13 +- .../log => base/io/log/backends}/SysLog.cpp | 15 +- .../log => base/io/log/backends}/SysLog.h | 8 +- .../kernel}/interfaces/ILogBackend.h | 18 +- src/base/net/stratum/Pools.cpp | 26 +- src/common/config/CommonConfig.cpp | 8 +- src/common/log/BasicLog.cpp | 90 ------- src/common/log/BasicLog.h | 57 ---- src/common/log/Log.cpp | 134 ---------- src/common/log/Log.h | 87 +------ src/core/Controller.cpp | 7 +- src/version.h | 4 +- src/workers/Workers.cpp | 4 +- 22 files changed, 489 insertions(+), 559 deletions(-) create mode 100644 src/base/io/log/Log.cpp create mode 100644 src/base/io/log/Log.h rename src/{common/log => base/io/log/backends}/ConsoleLog.cpp (64%) rename src/{common/log => base/io/log/backends}/ConsoleLog.h (84%) rename src/{common/log => base/io/log/backends}/FileLog.cpp (62%) rename src/{common/log => base/io/log/backends}/FileLog.h (85%) rename src/{common/log => base/io/log/backends}/SysLog.cpp (80%) rename src/{common/log => base/io/log/backends}/SysLog.h (85%) rename src/{common => base/kernel}/interfaces/ILogBackend.h (79%) delete mode 100644 src/common/log/BasicLog.cpp delete mode 100644 src/common/log/BasicLog.h delete mode 100644 src/common/log/Log.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index c8e68648..5c12f986 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,10 +33,6 @@ set(HEADERS src/common/interfaces/IConfigCreator.h src/common/interfaces/IControllerListener.h src/common/interfaces/ICpuInfo.h - src/common/interfaces/ILogBackend.h - src/common/log/BasicLog.h - src/common/log/ConsoleLog.h - src/common/log/FileLog.h src/common/log/Log.h src/common/Platform.h src/common/utils/mm_malloc.h @@ -92,10 +88,6 @@ set(SOURCES src/common/config/ConfigWatcher.cpp src/common/crypto/Algorithm.cpp src/common/crypto/keccak.cpp - src/common/log/BasicLog.cpp - src/common/log/ConsoleLog.cpp - src/common/log/FileLog.cpp - src/common/log/Log.cpp src/common/Platform.cpp src/core/Config.cpp src/core/Controller.cpp @@ -189,12 +181,6 @@ include(cmake/OpenSSL.cmake) include(cmake/asm.cmake) include(cmake/cn-gpu.cmake) -CHECK_INCLUDE_FILE (syslog.h HAVE_SYSLOG_H) -if (HAVE_SYSLOG_H) - add_definitions(/DHAVE_SYSLOG_H) - set(SOURCES_SYSLOG src/common/log/SysLog.h src/common/log/SysLog.cpp) -endif() - if (NOT WITH_AEON) add_definitions(/DXMRIG_NO_AEON) endif() diff --git a/src/App.cpp b/src/App.cpp index db91bab5..f33140c9 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -31,9 +31,9 @@ #include "api/Api.h" #include "App.h" #include "base/io/Console.h" +#include "base/io/log/Log.h" #include "base/kernel/Signals.h" #include "common/cpu/Cpu.h" -#include "common/log/Log.h" #include "common/Platform.h" #include "core/Config.h" #include "core/Controller.h" @@ -135,7 +135,7 @@ void xmrig::App::onConsoleCommand(char command) case 'p': case 'P': if (Workers::isEnabled()) { - LOG_INFO(m_controller->config()->isColors() ? "\x1B[01;33mpaused\x1B[0m, press \x1B[01;35mr\x1B[0m to resume" : "paused, press 'r' to resume"); + LOG_INFO(YELLOW_BOLD("paused") ", press " MAGENTA_BOLD("r") " to resume"); Workers::setEnabled(false); } break; @@ -143,7 +143,7 @@ void xmrig::App::onConsoleCommand(char command) case 'r': case 'R': if (!Workers::isEnabled()) { - LOG_INFO(m_controller->config()->isColors() ? "\x1B[01;32mresumed" : "resumed"); + LOG_INFO(GREEN_BOLD("resumed")); Workers::setEnabled(true); } break; @@ -194,5 +194,5 @@ void xmrig::App::close() m_controller->stop(); Workers::stop(); - Log::release(); + Log::destroy(); } diff --git a/src/Summary.cpp b/src/Summary.cpp index 78d624df..b5c63b59 100644 --- a/src/Summary.cpp +++ b/src/Summary.cpp @@ -59,11 +59,11 @@ inline static const char *asmName(xmrig::Assembly assembly, bool colors) static void print_memory(xmrig::Config *config) { # ifdef _WIN32 if (config->isColors()) { - xmrig::Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%s", + xmrig::Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%s", "HUGE PAGES", Mem::isHugepagesAvailable() ? "\x1B[1;32mavailable" : "\x1B[01;31munavailable"); } else { - xmrig::Log::i()->text(" * %-13s%s", "HUGE PAGES", Mem::isHugepagesAvailable() ? "available" : "unavailable"); + xmrig::Log::print(" * %-13s%s", "HUGE PAGES", Mem::isHugepagesAvailable() ? "available" : "unavailable"); } # endif } @@ -74,7 +74,7 @@ static void print_cpu(xmrig::Config *config) using namespace xmrig; if (config->isColors()) { - Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s%s (%d)") " %sx64 %sAES %sAVX2", + Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s%s (%d)") " %sx64 %sAES %sAVX2", "CPU", Cpu::info()->brand(), Cpu::info()->sockets(), @@ -82,11 +82,11 @@ static void print_cpu(xmrig::Config *config) Cpu::info()->hasAES() ? "\x1B[1;32m" : "\x1B[1;31m-", Cpu::info()->hasAVX2() ? "\x1B[1;32m" : "\x1B[1;31m-"); # ifndef XMRIG_NO_LIBCPUID - Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s%.1f MB/%.1f MB"), "CPU L2/L3", Cpu::info()->L2() / 1024.0, Cpu::info()->L3() / 1024.0); + Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s%.1f MB/%.1f MB"), "CPU L2/L3", Cpu::info()->L2() / 1024.0, Cpu::info()->L3() / 1024.0); # endif } else { - Log::i()->text(" * %-13s%s (%d) %sx64 %sAES %sAVX2", + Log::print(" * %-13s%s (%d) %sx64 %sAES %sAVX2", "CPU", Cpu::info()->brand(), Cpu::info()->sockets(), @@ -94,7 +94,7 @@ static void print_cpu(xmrig::Config *config) Cpu::info()->hasAES() ? "" : "-", Cpu::info()->hasAVX2() ? "" : "-"); # ifndef XMRIG_NO_LIBCPUID - Log::i()->text(" * %-13s%.1f MB/%.1f MB", "CPU L2/L3", Cpu::info()->L2() / 1024.0, Cpu::info()->L3() / 1024.0); + Log::print(" * %-13s%.1f MB/%.1f MB", "CPU L2/L3", Cpu::info()->L2() / 1024.0, Cpu::info()->L3() / 1024.0); # endif } } @@ -108,7 +108,7 @@ static void print_threads(xmrig::Config *config) snprintf(buf, sizeof buf, ", affinity=0x%" PRIX64, config->affinity()); } - xmrig::Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%d") WHITE_BOLD(", %s, av=%d, %sdonate=%d%%") WHITE_BOLD("%s") + xmrig::Log::print(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%d") WHITE_BOLD(", %s, av=%d, %sdonate=%d%%") WHITE_BOLD("%s") : " * %-13s%d, %s, av=%d, %sdonate=%d%%%s", "THREADS", config->threadsCount(), @@ -119,7 +119,7 @@ static void print_threads(xmrig::Config *config) buf); } else { - xmrig::Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%d") WHITE_BOLD(", %s, %sdonate=%d%%") + xmrig::Log::print(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%d") WHITE_BOLD(", %s, %sdonate=%d%%") : " * %-13s%d, %s, %sdonate=%d%%", "THREADS", config->threadsCount(), @@ -132,11 +132,11 @@ static void print_threads(xmrig::Config *config) if (config->assembly() == xmrig::ASM_AUTO) { const xmrig::Assembly assembly = xmrig::Cpu::info()->assembly(); - xmrig::Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13sauto:%s") + xmrig::Log::print(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13sauto:%s") : " * %-13sauto:%s", "ASSEMBLY", asmName(assembly, config->isColors())); } else { - xmrig::Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s%s") : " * %-13s%s", "ASSEMBLY", asmName(config->assembly(), config->isColors())); + xmrig::Log::print(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s%s") : " * %-13s%s", "ASSEMBLY", asmName(config->assembly(), config->isColors())); } # endif } @@ -145,12 +145,12 @@ static void print_threads(xmrig::Config *config) static void print_commands(xmrig::Config *config) { if (config->isColors()) { - xmrig::Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("COMMANDS ") MAGENTA_BOLD("h") WHITE_BOLD("ashrate, ") + xmrig::Log::print(GREEN_BOLD(" * ") WHITE_BOLD("COMMANDS ") MAGENTA_BOLD("h") WHITE_BOLD("ashrate, ") MAGENTA_BOLD("p") WHITE_BOLD("ause, ") MAGENTA_BOLD("r") WHITE_BOLD("esume")); } else { - xmrig::Log::i()->text(" * COMMANDS 'h' hashrate, 'p' pause, 'r' resume"); + xmrig::Log::print(" * COMMANDS 'h' hashrate, 'p' pause, 'r' resume"); } } diff --git a/src/base/base.cmake b/src/base/base.cmake index 08d86805..66bf74a8 100644 --- a/src/base/base.cmake +++ b/src/base/base.cmake @@ -1,6 +1,9 @@ set(HEADERS_BASE src/base/io/Console.h src/base/io/Json.h + src/base/io/log/backends/ConsoleLog.h + src/base/io/log/backends/FileLog.h + src/base/io/log/Log.h src/base/io/Watcher.h src/base/kernel/Entry.h src/base/kernel/interfaces/IClientListener.h @@ -8,6 +11,7 @@ set(HEADERS_BASE src/base/kernel/interfaces/IConsoleListener.h src/base/kernel/interfaces/IDnsListener.h src/base/kernel/interfaces/ILineListener.h + src/base/kernel/interfaces/ILogBackend.h src/base/kernel/interfaces/ISignalListener.h src/base/kernel/interfaces/IStrategy.h src/base/kernel/interfaces/IStrategyListener.h @@ -37,6 +41,9 @@ set(HEADERS_BASE set(SOURCES_BASE src/base/io/Console.cpp src/base/io/Json.cpp + src/base/io/log/backends/ConsoleLog.cpp + src/base/io/log/backends/FileLog.cpp + src/base/io/log/Log.cpp src/base/io/Watcher.cpp src/base/kernel/Entry.cpp src/base/kernel/Process.cpp @@ -61,3 +68,12 @@ if (WIN32) else() set(SOURCES_OS src/base/io/Json_unix.cpp) endif() + + +if (NOT WIN32) + CHECK_INCLUDE_FILE (syslog.h HAVE_SYSLOG_H) + if (HAVE_SYSLOG_H) + add_definitions(/DHAVE_SYSLOG_H) + set(SOURCES_SYSLOG src/base/log/backends/SysLog.h src/base/log/backends/SysLog.cpp) + endif() +endif() diff --git a/src/base/io/log/Log.cpp b/src/base/io/log/Log.cpp new file mode 100644 index 00000000..eec17760 --- /dev/null +++ b/src/base/io/log/Log.cpp @@ -0,0 +1,245 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2019 Spudz76 + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig , + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#ifdef WIN32 +# include +# include +#endif + + +#include +#include +#include +#include + + +#include "base/io/log/Log.h" +#include "base/kernel/interfaces/ILogBackend.h" + + +namespace xmrig { + + +static const char *colors_map[] = { + RED_BOLD_S, // EMERG + RED_BOLD_S, // ALERT + RED_BOLD_S, // CRIT + RED_S, // ERR + YELLOW_S, // WARNING + WHITE_BOLD_S, // NOTICE + nullptr, // INFO +# ifdef WIN32 + BLACK_BOLD_S // DEBUG +# else + BRIGHT_BLACK_S // DEBUG +# endif +}; + + + +class LogPrivate +{ +public: + inline LogPrivate() : + m_buf() + { + uv_mutex_init(&m_mutex); + } + + + inline ~LogPrivate() + { + uv_mutex_destroy(&m_mutex); + + for (ILogBackend *backend : m_backends) { + delete backend; + } + } + + + inline void add(ILogBackend *backend) { m_backends.push_back(backend); } + + + void print(Log::Level level, const char *fmt, va_list args) + { + size_t size = 0; + size_t offset = 0; + + lock(); + timestamp(level, size, offset); + color(level, size); + + int rc = vsnprintf(m_buf + size, sizeof (m_buf) - offset - 32, fmt, args); + if (rc < 0) { + return unlock(); + } + + size += static_cast(rc); + endl(size); + + std::string txt(m_buf); + size_t i; + while ((i = txt.find(CSI)) != std::string::npos) { + txt.erase(i, txt.find('m', i) - i + 1); + } + + if (!m_backends.empty()) { + for (ILogBackend *backend : m_backends) { + backend->print(level, m_buf, offset, size, true); + backend->print(level, txt.c_str(), offset, txt.size(), false); + } + } + else { + fputs(txt.c_str(), stdout); + fflush(stdout); + } + + unlock(); + } + + +private: + inline void lock() { uv_mutex_lock(&m_mutex); } + inline void unlock() { uv_mutex_unlock(&m_mutex); } + + + inline void timestamp(Log::Level level, size_t &size, size_t &offset) + { + if (level == Log::NONE) { + return; + } + + time_t now = time(nullptr); + tm stime; + +# ifdef _WIN32 + localtime_s(&stime, &now); +# else + localtime_r(&now, &stime); +# endif + + const int rc = snprintf(m_buf, sizeof(m_buf) - 1, "[%d-%02d-%02d %02d:%02d:%02d] ", + stime.tm_year + 1900, + stime.tm_mon + 1, + stime.tm_mday, + stime.tm_hour, + stime.tm_min, + stime.tm_sec + ); + + if (rc > 0) { + size = offset = static_cast(rc); + } + } + + + inline void color(Log::Level level, size_t &size) + { + if (level == Log::NONE) { + return; + } + + const char *color = colors_map[level]; + if (color == nullptr) { + return; + } + + const size_t s = strlen(color); + memcpy(m_buf + size, color, s); + + size += s; + } + + + inline void endl(size_t &size) + { +# ifdef _WIN32 + memcpy(m_buf + size, CLEAR "\r\n", 7); + size += 6; +# else + memcpy(m_buf + size, CLEAR "\n", 6); + size += 5; +# endif + } + + + char m_buf[4096]; + std::vector m_backends; + uv_mutex_t m_mutex; +}; + + +bool Log::colors = true; +LogPrivate *Log::d = new LogPrivate(); + + +} /* namespace xmrig */ + + + +void xmrig::Log::add(ILogBackend *backend) +{ + if (d) { + d->add(backend); + } +} + + +void xmrig::Log::destroy() +{ + delete d; + d = nullptr; +} + + +void xmrig::Log::print(const char *fmt, ...) +{ + if (!d) { + return; + } + + va_list args; + va_start(args, fmt); + + d->print(NONE, fmt, args); + + va_end(args); +} + + +void xmrig::Log::print(Level level, const char *fmt, ...) +{ + if (!d) { + return; + } + + va_list args; + va_start(args, fmt); + + d->print(level, fmt, args); + + va_end(args); +} diff --git a/src/base/io/log/Log.h b/src/base/io/log/Log.h new file mode 100644 index 00000000..a14ffded --- /dev/null +++ b/src/base/io/log/Log.h @@ -0,0 +1,129 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2019 Spudz76 + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig , + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef XMRIG_LOG_H +#define XMRIG_LOG_H + + +namespace xmrig { + + +class ILogBackend; +class LogPrivate; + + +class Log +{ +public: + enum Level : int { + NONE = -1, + EMERG, // system is unusable + ALERT, // action must be taken immediately + CRIT, // critical conditions + ERR, // error conditions + WARNING, // warning conditions + NOTICE, // normal but significant condition + INFO, // informational + DEBUG, // debug-level messages + }; + + static void add(ILogBackend *backend); + static void destroy(); + static void print(const char *fmt, ...); + static void print(Level level, const char *fmt, ...); + + static bool colors; + +private: + static LogPrivate *d; +}; + + +#define CSI "\x1B[" // Control Sequence Introducer (ANSI spec name) +#define CLEAR CSI "0m" // all attributes off +#define BRIGHT_BLACK_S CSI "0;90m" // somewhat MD.GRAY +#define BLACK_S CSI "0;30m" +#define BLACK_BOLD_S CSI "1;30m" // another name for GRAY +#define RED_S CSI "0;31m" +#define RED_BOLD_S CSI "1;31m" +#define GREEN_S CSI "0;32m" +#define GREEN_BOLD_S CSI "1;32m" +#define YELLOW_S CSI "0;33m" +#define YELLOW_BOLD_S CSI "1;33m" +#define BLUE_S CSI "0;34m" +#define BLUE_BOLD_S CSI "1;34m" +#define MAGENTA_S CSI "0;35m" +#define MAGENTA_BOLD_S CSI "1;35m" +#define CYAN_S CSI "0;36m" +#define CYAN_BOLD_S CSI "1;36m" +#define WHITE_S CSI "0;37m" // another name for LT.GRAY +#define WHITE_BOLD_S CSI "1;37m" // actually white + +//color wrappings +#define BLACK(x) BLACK_S x CLEAR +#define BLACK_BOLD(x) BLACK_BOLD_S x CLEAR +#define RED(x) RED_S x CLEAR +#define RED_BOLD(x) RED_BOLD_S x CLEAR +#define GREEN(x) GREEN_S x CLEAR +#define GREEN_BOLD(x) GREEN_BOLD_S x CLEAR +#define YELLOW(x) YELLOW_S x CLEAR +#define YELLOW_BOLD(x) YELLOW_BOLD_S x CLEAR +#define BLUE(x) BLUE_S x CLEAR +#define BLUE_BOLD(x) BLUE_BOLD_S x CLEAR +#define MAGENTA(x) MAGENTA_S x CLEAR +#define MAGENTA_BOLD(x) MAGENTA_BOLD_S x CLEAR +#define CYAN(x) CYAN_S x CLEAR +#define CYAN_BOLD(x) CYAN_BOLD_S x CLEAR +#define WHITE(x) WHITE_S x CLEAR +#define WHITE_BOLD(x) WHITE_BOLD_S x CLEAR + + +#define LOG_EMERG(x, ...) xmrig::Log::print(xmrig::Log::EMERG, x, ##__VA_ARGS__) +#define LOG_ALERT(x, ...) xmrig::Log::print(xmrig::Log::ALERT, x, ##__VA_ARGS__) +#define LOG_CRIT(x, ...) xmrig::Log::print(xmrig::Log::CRIT, x, ##__VA_ARGS__) +#define LOG_ERR(x, ...) xmrig::Log::print(xmrig::Log::ERR, x, ##__VA_ARGS__) +#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__) + +#ifdef APP_DEBUG +# define LOG_DEBUG(x, ...) xmrig::Log::print(xmrig::Log::DEBUG, x, ##__VA_ARGS__) +#else +# define LOG_DEBUG(x, ...) +#endif + +#if defined(APP_DEBUG) || defined(APP_DEVEL) +# define LOG_DEBUG_ERR(x, ...) xmrig::Log::print(xmrig::Log::ERR, x, ##__VA_ARGS__) +# define LOG_DEBUG_WARN(x, ...) xmrig::Log::print(xmrig::Log::WARNING, x, ##__VA_ARGS__) +#else +# define LOG_DEBUG_ERR(x, ...) +# define LOG_DEBUG_WARN(x, ...) +#endif + + +} /* namespace xmrig */ + + +#endif /* XMRIG_LOG_H */ diff --git a/src/common/log/ConsoleLog.cpp b/src/base/io/log/backends/ConsoleLog.cpp similarity index 64% rename from src/common/log/ConsoleLog.cpp rename to src/base/io/log/backends/ConsoleLog.cpp index e0ac01ea..a5b6c1a7 100644 --- a/src/common/log/ConsoleLog.cpp +++ b/src/base/io/log/backends/ConsoleLog.cpp @@ -5,6 +5,7 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , + * Copyright 2019 Spudz76 * Copyright 2018-2019 SChernykh * Copyright 2016-2019 XMRig , * @@ -23,21 +24,12 @@ */ -#include #include -#include -#include -#include - -#ifdef WIN32 -# include -# include -#endif #include "base/tools/Handle.h" -#include "common/log/ConsoleLog.h" -#include "common/log/Log.h" +#include "base/io/log/backends/ConsoleLog.h" +#include "base/io/log/Log.h" xmrig::ConsoleLog::ConsoleLog() : @@ -51,8 +43,7 @@ xmrig::ConsoleLog::ConsoleLog() : } uv_tty_set_mode(m_tty, UV_TTY_MODE_NORMAL); - m_uvBuf.base = m_buf; - m_stream = reinterpret_cast(m_tty); + m_stream = reinterpret_cast(m_tty); # ifdef WIN32 HANDLE handle = GetStdHandle(STD_INPUT_HANDLE); @@ -73,38 +64,25 @@ xmrig::ConsoleLog::~ConsoleLog() } -void xmrig::ConsoleLog::message(Level level, const char* fmt, va_list args) +void xmrig::ConsoleLog::print(int, const char *line, size_t, size_t size, bool colors) { - time_t now = time(nullptr); - tm stime; + if (Log::colors != colors) { + return; + } # ifdef _WIN32 - localtime_s(&stime, &now); + uv_buf_t buf = uv_buf_init(const_cast(line), static_cast(size)); # else - localtime_r(&now, &stime); + uv_buf_t buf = uv_buf_init(const_cast(line), size); # endif - snprintf(m_fmt, sizeof(m_fmt) - 1, "[%d-%02d-%02d %02d:%02d:%02d]%s %s%s", - stime.tm_year + 1900, - stime.tm_mon + 1, - stime.tm_mday, - stime.tm_hour, - stime.tm_min, - stime.tm_sec, - Log::colorByLevel(level, Log::colors), - fmt, - Log::endl(Log::colors) - ); - - print(args); -} - - -void xmrig::ConsoleLog::text(const char* fmt, va_list args) -{ - snprintf(m_fmt, sizeof(m_fmt) - 1, "%s%s", fmt, Log::endl(Log::colors)); - - print(args); + if (!isWritable()) { + fputs(line, stdout); + fflush(stdout); + } + else { + uv_try_write(m_stream, &buf, 1); + } } @@ -117,20 +95,3 @@ bool xmrig::ConsoleLog::isWritable() const const uv_handle_type type = uv_guess_handle(1); return type == UV_TTY || type == UV_NAMED_PIPE; } - - -void xmrig::ConsoleLog::print(va_list args) -{ - m_uvBuf.len = vsnprintf(m_buf, sizeof(m_buf) - 1, m_fmt, args); - if (m_uvBuf.len <= 0) { - return; - } - - if (!isWritable()) { - fputs(m_buf, stdout); - fflush(stdout); - } - else { - uv_try_write(m_stream, &m_uvBuf, 1); - } -} diff --git a/src/common/log/ConsoleLog.h b/src/base/io/log/backends/ConsoleLog.h similarity index 84% rename from src/common/log/ConsoleLog.h rename to src/base/io/log/backends/ConsoleLog.h index 73a701e6..90e4fa14 100644 --- a/src/common/log/ConsoleLog.h +++ b/src/base/io/log/backends/ConsoleLog.h @@ -5,6 +5,7 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , + * Copyright 2019 Spudz76 * Copyright 2018-2019 SChernykh * Copyright 2016-2019 XMRig , * @@ -26,10 +27,11 @@ #define XMRIG_CONSOLELOG_H -#include +typedef struct uv_stream_s uv_stream_t; +typedef struct uv_tty_s uv_tty_t; -#include "common/interfaces/ILogBackend.h" +#include "base/kernel/interfaces/ILogBackend.h" namespace xmrig { @@ -42,16 +44,11 @@ public: ~ConsoleLog() override; protected: - void message(Level level, const char *fmt, va_list args) override; - void text(const char *fmt, va_list args) override; + void print(int level, const char *line, size_t offset, size_t size, bool colors) override; private: bool isWritable() const; - void print(va_list args); - char m_buf[kBufferSize]; - char m_fmt[256]; - uv_buf_t m_uvBuf; uv_stream_t *m_stream; uv_tty_t *m_tty; }; diff --git a/src/common/log/FileLog.cpp b/src/base/io/log/backends/FileLog.cpp similarity index 62% rename from src/common/log/FileLog.cpp rename to src/base/io/log/backends/FileLog.cpp index 71eeb18c..82c8407e 100644 --- a/src/common/log/FileLog.cpp +++ b/src/base/io/log/backends/FileLog.cpp @@ -5,6 +5,7 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , + * Copyright 2019 Spudz76 * Copyright 2018-2019 SChernykh * Copyright 2016-2019 XMRig , * @@ -23,15 +24,10 @@ */ -#include -#include -#include -#include -#include +#include -#include "common/log/FileLog.h" -#include "common/log/Log.h" +#include "base/io/log/backends/FileLog.h" xmrig::FileLog::FileLog(const char *fileName) @@ -42,43 +38,22 @@ xmrig::FileLog::FileLog(const char *fileName) } -void xmrig::FileLog::message(Level level, const char* fmt, va_list args) +void xmrig::FileLog::print(int, const char *line, size_t, size_t size, bool colors) { - if (m_file < 0) { + if (m_file < 0 || colors) { return; } - time_t now = time(nullptr); - tm stime; - # ifdef _WIN32 - localtime_s(&stime, &now); + uv_buf_t buf = uv_buf_init(strdup(line), static_cast(size)); # else - localtime_r(&now, &stime); + uv_buf_t buf = uv_buf_init(strdup(line), size); # endif - snprintf(m_fmt, sizeof(m_fmt) - 1, "[%d-%02d-%02d %02d:%02d:%02d]%s %s%s", - stime.tm_year + 1900, - stime.tm_mon + 1, - stime.tm_mday, - stime.tm_hour, - stime.tm_min, - stime.tm_sec, - Log::colorByLevel(level, Log::colors), - fmt, - Log::endl(Log::colors) - ); + uv_fs_t *req = new uv_fs_t; + req->data = buf.base; - char *buf = new char[kBufferSize]; - const int size = vsnprintf(buf, kBufferSize - 1, m_fmt, args); - - write(buf, size); -} - - -void xmrig::FileLog::text(const char* fmt, va_list args) -{ - message(INFO, fmt, args); + uv_fs_write(uv_default_loop(), req, m_file, &buf, 1, -1, FileLog::onWrite); } @@ -89,13 +64,3 @@ void xmrig::FileLog::onWrite(uv_fs_t *req) uv_fs_req_cleanup(req); delete req; } - - -void xmrig::FileLog::write(char *data, size_t size) -{ - uv_buf_t buf = uv_buf_init(data, (unsigned int) size); - uv_fs_t *req = new uv_fs_t; - req->data = buf.base; - - uv_fs_write(uv_default_loop(), req, m_file, &buf, 1, -1, FileLog::onWrite); -} diff --git a/src/common/log/FileLog.h b/src/base/io/log/backends/FileLog.h similarity index 85% rename from src/common/log/FileLog.h rename to src/base/io/log/backends/FileLog.h index da80acb2..188a99aa 100644 --- a/src/common/log/FileLog.h +++ b/src/base/io/log/backends/FileLog.h @@ -5,6 +5,7 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , + * Copyright 2019 Spudz76 * Copyright 2018-2019 SChernykh * Copyright 2016-2019 XMRig , * @@ -26,10 +27,10 @@ #define XMRIG_FILELOG_H -#include +typedef struct uv_fs_s uv_fs_t; -#include "common/interfaces/ILogBackend.h" +#include "base/kernel/interfaces/ILogBackend.h" namespace xmrig { @@ -40,15 +41,13 @@ class FileLog : public ILogBackend public: FileLog(const char *fileName); - void message(Level level, const char* fmt, va_list args) override; - void text(const char* fmt, va_list args) override; + +protected: + void print(int level, const char *line, size_t offset, size_t size, bool colors) override; private: static void onWrite(uv_fs_t *req); - void write(char *data, size_t size); - - char m_fmt[256]; int m_file; }; diff --git a/src/common/log/SysLog.cpp b/src/base/io/log/backends/SysLog.cpp similarity index 80% rename from src/common/log/SysLog.cpp rename to src/base/io/log/backends/SysLog.cpp index 1a8ffbd2..b75973f1 100644 --- a/src/common/log/SysLog.cpp +++ b/src/base/io/log/backends/SysLog.cpp @@ -5,6 +5,7 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , + * Copyright 2019 Spudz76 * Copyright 2018-2019 SChernykh * Copyright 2016-2019 XMRig , * @@ -26,7 +27,7 @@ #include -#include "common/log/SysLog.h" +#include "base/io/log/backends/SysLog.h" #include "version.h" @@ -36,13 +37,17 @@ xmrig::SysLog::SysLog() } -void xmrig::SysLog::message(Level level, const char *fmt, va_list args) +xmrig::SysLog::~SysLog() { - vsyslog(static_cast(level), fmt, args); + closelog(); } -void xmrig::SysLog::text(const char *fmt, va_list args) +void xmrig::SysLog::print(int level, const char *line, size_t offset, size_t, bool colors) { - vsyslog(LOG_INFO, fmt, args); + if (colors) { + return; + } + + syslog(level == -1 ? LOG_INFO : level, line + offset); } diff --git a/src/common/log/SysLog.h b/src/base/io/log/backends/SysLog.h similarity index 85% rename from src/common/log/SysLog.h rename to src/base/io/log/backends/SysLog.h index 3e64cf8b..0e8d0f8e 100644 --- a/src/common/log/SysLog.h +++ b/src/base/io/log/backends/SysLog.h @@ -5,6 +5,7 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , + * Copyright 2019 Spudz76 * Copyright 2018-2019 SChernykh * Copyright 2016-2019 XMRig , * @@ -26,7 +27,7 @@ #define XMRIG_SYSLOG_H -#include "common/interfaces/ILogBackend.h" +#include "base/kernel/interfaces/ILogBackend.h" namespace xmrig { @@ -36,9 +37,10 @@ class SysLog : public ILogBackend { public: SysLog(); + ~SysLog(); - void message(Level level, const char *fmt, va_list args) override; - void text(const char *fmt, va_list args) override; +protected: + void print(int level, const char *line, size_t offset, size_t size, bool colors) override; }; diff --git a/src/common/interfaces/ILogBackend.h b/src/base/kernel/interfaces/ILogBackend.h similarity index 79% rename from src/common/interfaces/ILogBackend.h rename to src/base/kernel/interfaces/ILogBackend.h index 2299fc67..ef18da88 100644 --- a/src/common/interfaces/ILogBackend.h +++ b/src/base/kernel/interfaces/ILogBackend.h @@ -5,6 +5,7 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , + * Copyright 2019 Spudz76 * Copyright 2018-2019 SChernykh * Copyright 2016-2019 XMRig , * @@ -36,24 +37,9 @@ namespace xmrig { class ILogBackend { public: - enum Level { - ERR, - WARNING, - NOTICE, - INFO, - DEBUG - }; - -# ifdef APP_DEBUG - constexpr static const size_t kBufferSize = 1024; -# else - constexpr static const size_t kBufferSize = 512; -# endif - virtual ~ILogBackend() = default; - virtual void message(Level level, const char* fmt, va_list args) = 0; - virtual void text(const char* fmt, va_list args) = 0; + virtual void print(int level, const char *line, size_t offset, size_t size, bool colors) = 0; }; diff --git a/src/base/net/stratum/Pools.cpp b/src/base/net/stratum/Pools.cpp index fc132dd5..f2d34287 100644 --- a/src/base/net/stratum/Pools.cpp +++ b/src/base/net/stratum/Pools.cpp @@ -164,21 +164,21 @@ void xmrig::Pools::print() const if (Log::colors) { const int color = pool.isEnabled() ? (pool.isTLS() ? 32 : 36) : 31; - Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("POOL #%-7zu") "\x1B[1;%dm%s\x1B[0m variant " WHITE_BOLD("%s"), - i, - color, - pool.url().data(), - pool.algorithm().variantName() - ); + Log::print(GREEN_BOLD(" * ") WHITE_BOLD("POOL #%-7zu") "\x1B[1;%dm%s\x1B[0m variant " WHITE_BOLD("%s"), + i, + color, + pool.url().data(), + pool.algorithm().variantName() + ); } else { - Log::i()->text(" * POOL #%-7zu%s%s variant=%s %s", - i, - pool.isEnabled() ? "" : "-", - pool.url().data(), - pool.algorithm().variantName(), - pool.isTLS() ? "TLS" : "" - ); + Log::print(" * POOL #%-7zu%s%s variant=%s %s", + i, + pool.isEnabled() ? "" : "-", + pool.url().data(), + pool.algorithm().variantName(), + pool.isTLS() ? "TLS" : "" + ); } i++; diff --git a/src/common/config/CommonConfig.cpp b/src/common/config/CommonConfig.cpp index 94bbd59f..1be36426 100644 --- a/src/common/config/CommonConfig.cpp +++ b/src/common/config/CommonConfig.cpp @@ -93,7 +93,7 @@ void xmrig::CommonConfig::printAPI() return; } - Log::i()->text(isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN("%s:") CYAN_BOLD("%d") + Log::print(isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN("%s:") CYAN_BOLD("%d") : " * %-13s%s:%d", "API BIND", isApiIPv6() ? "[::]" : "0.0.0.0", apiPort()); # endif @@ -118,7 +118,7 @@ void xmrig::CommonConfig::printVersions() snprintf(buf, sizeof buf, "MSVC/%d", MSVC_VERSION); # endif - Log::i()->text(isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%s/%s") WHITE_BOLD(" %s") + Log::print(isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%s/%s") WHITE_BOLD(" %s") : " * %-13s%s/%s %s", "ABOUT", APP_NAME, APP_VERSION, buf); @@ -157,8 +157,8 @@ void xmrig::CommonConfig::printVersions() length += snprintf(buf + length, (sizeof buf) - length, "microhttpd/%s ", MHD_get_version()); # endif - Log::i()->text(isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13slibuv/%s %s") - : " * %-13slibuv/%s %s", + Log::print(isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13slibuv/%s %s") + : " * %-13slibuv/%s %s", "LIBS", uv_version_string(), buf); } diff --git a/src/common/log/BasicLog.cpp b/src/common/log/BasicLog.cpp deleted file mode 100644 index b048dd6e..00000000 --- a/src/common/log/BasicLog.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* XMRig - * Copyright 2010 Jeff Garzik - * Copyright 2012-2014 pooler - * Copyright 2014 Lucas Jones - * Copyright 2014-2016 Wolf9466 - * Copyright 2016 Jay D Dee - * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - - -#include -#include -#include -#include -#include - -#ifdef WIN32 -# include -# include -#endif - - -#include "common/log/BasicLog.h" -#include "common/log/Log.h" - - -xmrig::BasicLog::BasicLog() -{ -} - - -void xmrig::BasicLog::message(Level level, const char* fmt, va_list args) -{ - time_t now = time(nullptr); - tm stime; - -# ifdef _WIN32 - localtime_s(&stime, &now); -# else - localtime_r(&now, &stime); -# endif - - snprintf(m_fmt, sizeof(m_fmt) - 1, "[%d-%02d-%02d %02d:%02d:%02d]%s %s%s", - stime.tm_year + 1900, - stime.tm_mon + 1, - stime.tm_mday, - stime.tm_hour, - stime.tm_min, - stime.tm_sec, - Log::colorByLevel(level, false), - fmt, - Log::endl(false) - ); - - print(args); -} - - -void xmrig::BasicLog::text(const char* fmt, va_list args) -{ - snprintf(m_fmt, sizeof(m_fmt) - 1, "%s%s", fmt, Log::endl(false)); - - print(args); -} - - -void xmrig::BasicLog::print(va_list args) -{ - if (vsnprintf(m_buf, sizeof(m_buf) - 1, m_fmt, args) <= 0) { - return; - } - - fputs(m_buf, stdout); - fflush(stdout); -} diff --git a/src/common/log/BasicLog.h b/src/common/log/BasicLog.h deleted file mode 100644 index bddbe07c..00000000 --- a/src/common/log/BasicLog.h +++ /dev/null @@ -1,57 +0,0 @@ -/* XMRig - * Copyright 2010 Jeff Garzik - * Copyright 2012-2014 pooler - * Copyright 2014 Lucas Jones - * Copyright 2014-2016 Wolf9466 - * Copyright 2016 Jay D Dee - * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef XMRIG_BASICLOG_H -#define XMRIG_BASICLOG_H - - -#include - - -#include "common/interfaces/ILogBackend.h" - - -namespace xmrig { - - -class BasicLog : public ILogBackend -{ -public: - BasicLog(); - - void message(Level level, const char *fmt, va_list args) override; - void text(const char *fmt, va_list args) override; - -private: - bool isWritable() const; - void print(va_list args); - - char m_buf[kBufferSize]; - char m_fmt[256]; -}; - - -} /* namespace xmrig */ - -#endif /* XMRIG_BASICLOG_H */ diff --git a/src/common/log/Log.cpp b/src/common/log/Log.cpp deleted file mode 100644 index 4ef1e14a..00000000 --- a/src/common/log/Log.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/* XMRig - * Copyright 2010 Jeff Garzik - * Copyright 2012-2014 pooler - * Copyright 2014 Lucas Jones - * Copyright 2014-2016 Wolf9466 - * Copyright 2016 Jay D Dee - * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - - -#include -#include -#include -#include -#include - - -#include "common/interfaces/ILogBackend.h" -#include "common/log/BasicLog.h" -#include "common/log/Log.h" - - -namespace xmrig { - -Log *Log::m_self = nullptr; -bool Log::colors = true; - - -static const char *color[5] = { - "\x1B[0;31m", /* ERR */ - "\x1B[0;33m", /* WARNING */ - "\x1B[1;37m", /* NOTICE */ - "", /* INFO */ -# ifdef WIN32 - "\x1B[1;30m" /* DEBUG */ -# else - "\x1B[90m" /* DEBUG */ -# endif -}; - -} /* namespace xmrig */ - - -void xmrig::Log::message(ILogBackend::Level level, const char* fmt, ...) -{ - uv_mutex_lock(&m_mutex); - - va_list args; - va_list copy; - va_start(args, fmt); - - for (ILogBackend *backend : m_backends) { - va_copy(copy, args); - backend->message(level, fmt, copy); - va_end(copy); - } - - va_end(args); - - uv_mutex_unlock(&m_mutex); -} - - -void xmrig::Log::text(const char* fmt, ...) -{ - uv_mutex_lock(&m_mutex); - - va_list args; - va_list copy; - va_start(args, fmt); - - for (ILogBackend *backend : m_backends) { - va_copy(copy, args); - backend->text(fmt, copy); - va_end(copy); - } - - va_end(args); - - uv_mutex_unlock(&m_mutex); -} - - -const char *xmrig::Log::colorByLevel(ILogBackend::Level level, bool isColors) -{ - if (!isColors) { - return ""; - } - - return color[level]; -} - - -const char *xmrig::Log::endl(bool isColors) -{ -# ifdef _WIN32 - return isColors ? "\x1B[0m\r\n" : "\r\n"; -# else - return isColors ? "\x1B[0m\n" : "\n"; -# endif -} - - -void xmrig::Log::defaultInit() -{ - m_self = new Log(); - - add(new BasicLog()); -} - - -xmrig::Log::~Log() -{ - m_self = nullptr; - - for (auto backend : m_backends) { - delete backend; - } -} diff --git a/src/common/log/Log.h b/src/common/log/Log.h index 9a0ba2a9..f393b1da 100644 --- a/src/common/log/Log.h +++ b/src/common/log/Log.h @@ -22,90 +22,11 @@ * along with this program. If not, see . */ -#ifndef XMRIG_LOG_H -#define XMRIG_LOG_H +#ifndef XMRIG_LOG_LEGACY_H +#define XMRIG_LOG_LEGACY_H -#include -#include -#include +#include "base/io/log/Log.h" -#include "common/interfaces/ILogBackend.h" - - -namespace xmrig { - - -class Log -{ -public: - static inline Log* i() { if (!m_self) { defaultInit(); } return m_self; } - static inline void add(ILogBackend *backend) { i()->m_backends.push_back(backend); } - static inline void init() { if (!m_self) { new Log(); } } - static inline void release() { delete m_self; } - - void message(ILogBackend::Level level, const char* fmt, ...); - void text(const char* fmt, ...); - - static const char *colorByLevel(ILogBackend::Level level, bool isColors = true); - static const char *endl(bool isColors = true); - static void defaultInit(); - - static bool colors; - -private: - inline Log() { - assert(m_self == nullptr); - - uv_mutex_init(&m_mutex); - - m_self = this; - } - - ~Log(); - - static Log *m_self; - std::vector m_backends; - uv_mutex_t m_mutex; -}; - - -} /* namespace xmrig */ - - -#define RED_BOLD(x) "\x1B[1;31m" x "\x1B[0m" -#define RED(x) "\x1B[0;31m" x "\x1B[0m" -#define GREEN_BOLD(x) "\x1B[1;32m" x "\x1B[0m" -#define GREEN(x) "\x1B[0;32m" x "\x1B[0m" -#define YELLOW(x) "\x1B[0;33m" x "\x1B[0m" -#define YELLOW_BOLD(x) "\x1B[1;33m" x "\x1B[0m" -#define MAGENTA_BOLD(x) "\x1B[1;35m" x "\x1B[0m" -#define MAGENTA(x) "\x1B[0;35m" x "\x1B[0m" -#define CYAN_BOLD(x) "\x1B[1;36m" x "\x1B[0m" -#define CYAN(x) "\x1B[0;36m" x "\x1B[0m" -#define WHITE_BOLD(x) "\x1B[1;37m" x "\x1B[0m" -#define WHITE(x) "\x1B[0;37m" x "\x1B[0m" -#define GRAY(x) "\x1B[1;30m" x "\x1B[0m" - - -#define LOG_ERR(x, ...) xmrig::Log::i()->message(xmrig::ILogBackend::ERR, x, ##__VA_ARGS__) -#define LOG_WARN(x, ...) xmrig::Log::i()->message(xmrig::ILogBackend::WARNING, x, ##__VA_ARGS__) -#define LOG_NOTICE(x, ...) xmrig::Log::i()->message(xmrig::ILogBackend::NOTICE, x, ##__VA_ARGS__) -#define LOG_INFO(x, ...) xmrig::Log::i()->message(xmrig::ILogBackend::INFO, x, ##__VA_ARGS__) - -#ifdef APP_DEBUG -# define LOG_DEBUG(x, ...) xmrig::Log::i()->message(xmrig::ILogBackend::DEBUG, x, ##__VA_ARGS__) -#else -# define LOG_DEBUG(x, ...) -#endif - -#if defined(APP_DEBUG) || defined(APP_DEVEL) -# define LOG_DEBUG_ERR(x, ...) xmrig::Log::i()->message(xmrig::ILogBackend::ERR, x, ##__VA_ARGS__) -# define LOG_DEBUG_WARN(x, ...) xmrig::Log::i()->message(xmrig::ILogBackend::WARNING, x, ##__VA_ARGS__) -#else -# define LOG_DEBUG_ERR(x, ...) -# define LOG_DEBUG_WARN(x, ...) -#endif - -#endif /* XMRIG_LOG_H */ +#endif /* XMRIG_LOG_LEGACY_H */ diff --git a/src/core/Controller.cpp b/src/core/Controller.cpp index cfd132dd..6088034b 100644 --- a/src/core/Controller.cpp +++ b/src/core/Controller.cpp @@ -26,11 +26,11 @@ #include +#include "base/io/log/backends/ConsoleLog.h" +#include "base/io/log/backends/FileLog.h" #include "common/config/ConfigLoader.h" #include "common/cpu/Cpu.h" #include "common/interfaces/IControllerListener.h" -#include "common/log/ConsoleLog.h" -#include "common/log/FileLog.h" #include "common/log/Log.h" #include "common/Platform.h" #include "core/Config.h" @@ -39,7 +39,7 @@ #ifdef HAVE_SYSLOG_H -# include "common/log/SysLog.h" +# include "base/io/log/backends/SysLog.h" #endif @@ -102,7 +102,6 @@ int xmrig::Controller::init() return 1; } - Log::init(); Platform::init(config()->userAgent()); Platform::setProcessPriority(d_ptr->config->priority()); diff --git a/src/version.h b/src/version.h index 2c6eb6ef..117f1d6a 100644 --- a/src/version.h +++ b/src/version.h @@ -28,7 +28,7 @@ #define APP_ID "xmrig" #define APP_NAME "XMRig" #define APP_DESC "XMRig CPU miner" -#define APP_VERSION "2.15.0-beta" +#define APP_VERSION "2.15.1-evo" #define APP_DOMAIN "xmrig.com" #define APP_SITE "www.xmrig.com" #define APP_COPYRIGHT "Copyright (C) 2016-2019 xmrig.com" @@ -36,7 +36,7 @@ #define APP_VER_MAJOR 2 #define APP_VER_MINOR 15 -#define APP_VER_PATCH 0 +#define APP_VER_PATCH 1 #ifdef _MSC_VER # if (_MSC_VER >= 1910) diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index 5426762e..4adf349f 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -104,11 +104,11 @@ void Workers::printHashrate(bool detail) char num2[8] = { 0 }; char num3[8] = { 0 }; - xmrig::Log::i()->text("%s| THREAD | AFFINITY | 10s H/s | 60s H/s | 15m H/s |", isColors ? "\x1B[1;37m" : ""); + xmrig::Log::print("%s| THREAD | AFFINITY | 10s H/s | 60s H/s | 15m H/s |", isColors ? "\x1B[1;37m" : ""); size_t i = 0; for (const xmrig::IThread *thread : m_controller->config()->threads()) { - xmrig::Log::i()->text("| %6zu | %8" PRId64 " | %7s | %7s | %7s |", + xmrig::Log::print("| %6zu | %8" PRId64 " | %7s | %7s | %7s |", thread->index(), thread->affinity(), Hashrate::format(m_hashrate->calc(thread->index(), Hashrate::ShortInterval), num1, sizeof num1),