diff --git a/CMakeLists.txt b/CMakeLists.txt index 685aa5d3..4f2c4372 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,11 +7,11 @@ option(WITH_AEON "CryptoNight-Lite support" ON) set(HEADERS src/3rdparty/align.h src/App.h - src/Console.h src/Cpu.h src/interfaces/IClientListener.h src/interfaces/IJobResultListener.h src/interfaces/IWorker.h + src/log/Log.h src/Mem.h src/net/Client.h src/net/Job.h @@ -45,7 +45,7 @@ set(HEADERS_CRYPTO set(SOURCES src/App.cpp - src/Console.cpp + src/log/Log.cpp src/Mem.cpp src/net/Client.cpp src/net/Job.cpp diff --git a/src/App.cpp b/src/App.cpp index 4284bd69..3586889b 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -27,7 +27,7 @@ #include "App.h" -#include "Console.h" +#include "log/Log.h" #include "Cpu.h" #include "crypto/CryptoNight.h" #include "Mem.h" @@ -51,7 +51,7 @@ App::App(int argc, char **argv) : Cpu::init(); m_options = Options::parse(argc, argv); - Console::init(m_options->colors(), m_options->background()); + Log::init(m_options->colors(), m_options->background()); m_network = new Network(m_options); diff --git a/src/Mem_win.cpp b/src/Mem_win.cpp index c5e606f7..f47b6ae4 100644 --- a/src/Mem_win.cpp +++ b/src/Mem_win.cpp @@ -33,7 +33,7 @@ # include #endif -#include "Console.h" +#include "log/Log.h" #include "crypto/CryptoNight.h" #include "Mem.h" #include "Options.h" diff --git a/src/Summary.cpp b/src/Summary.cpp index 8f917d44..a243d9de 100644 --- a/src/Summary.cpp +++ b/src/Summary.cpp @@ -25,8 +25,8 @@ #include -#include "Console.h" #include "Cpu.h" +#include "log/Log.h" #include "Mem.h" #include "net/Url.h" #include "Options.h" @@ -50,21 +50,21 @@ static void print_versions() if (Options::i()->colors()) { - Console::i()->text("\x1B[01;32m * \x1B[01;37mVERSIONS: \x1B[01;36mXMRig/%s\x1B[01;37m libuv/%s%s", APP_VERSION, uv_version_string(), buf); + Log::i()->text("\x1B[01;32m * \x1B[01;37mVERSIONS: \x1B[01;36mXMRig/%s\x1B[01;37m libuv/%s%s", APP_VERSION, uv_version_string(), buf); } else { - Console::i()->text(" * VERSIONS: XMRig/%s libuv/%s%s", APP_VERSION, uv_version_string(), buf); + Log::i()->text(" * VERSIONS: XMRig/%s libuv/%s%s", APP_VERSION, uv_version_string(), buf); } } static void print_memory() { if (Options::i()->colors()) { - Console::i()->text("\x1B[01;32m * \x1B[01;37mHUGE PAGES: %s, %s", - Mem::isHugepagesAvailable() ? "\x1B[01;32mavailable" : "\x1B[01;31munavailable", - Mem::isHugepagesEnabled() ? "\x1B[01;32menabled" : "\x1B[01;31mdisabled"); + Log::i()->text("\x1B[01;32m * \x1B[01;37mHUGE PAGES: %s, %s", + Mem::isHugepagesAvailable() ? "\x1B[01;32mavailable" : "\x1B[01;31munavailable", + Mem::isHugepagesEnabled() ? "\x1B[01;32menabled" : "\x1B[01;31mdisabled"); } else { - Console::i()->text(" * HUGE PAGES: %s, %s", Mem::isHugepagesAvailable() ? "available" : "unavailable", Mem::isHugepagesEnabled() ? "enabled" : "disabled"); + Log::i()->text(" * HUGE PAGES: %s, %s", Mem::isHugepagesAvailable() ? "available" : "unavailable", Mem::isHugepagesEnabled() ? "enabled" : "disabled"); } } @@ -72,19 +72,19 @@ static void print_memory() { static void print_cpu() { if (Options::i()->colors()) { - Console::i()->text("\x1B[01;32m * \x1B[01;37mCPU: %s (%d) %sx64 %sAES-NI", - Cpu::brand(), - Cpu::sockets(), - Cpu::isX64() ? "\x1B[01;32m" : "\x1B[01;31m-", - Cpu::hasAES() ? "\x1B[01;32m" : "\x1B[01;31m-"); + Log::i()->text("\x1B[01;32m * \x1B[01;37mCPU: %s (%d) %sx64 %sAES-NI", + Cpu::brand(), + Cpu::sockets(), + Cpu::isX64() ? "\x1B[01;32m" : "\x1B[01;31m-", + Cpu::hasAES() ? "\x1B[01;32m" : "\x1B[01;31m-"); # ifndef XMRIG_NO_LIBCPUID - Console::i()->text("\x1B[01;32m * \x1B[01;37mCPU L2/L3: %.1f MB/%.1f MB", Cpu::l2() / 1024.0, Cpu::l3() / 1024.0); + Log::i()->text("\x1B[01;32m * \x1B[01;37mCPU L2/L3: %.1f MB/%.1f MB", Cpu::l2() / 1024.0, Cpu::l3() / 1024.0); # endif } else { - Console::i()->text(" * CPU: %s (%d) %sx64 %sAES-NI", Cpu::brand(), Cpu::sockets(), Cpu::isX64() ? "" : "-", Cpu::hasAES() ? "" : "-"); + Log::i()->text(" * CPU: %s (%d) %sx64 %sAES-NI", Cpu::brand(), Cpu::sockets(), Cpu::isX64() ? "" : "-", Cpu::hasAES() ? "" : "-"); # ifndef XMRIG_NO_LIBCPUID - Console::i()->text(" * CPU L2/L3: %.1f MB/%.1f MB", Cpu::l2() / 1024.0, Cpu::l3() / 1024.0); + Log::i()->text(" * CPU L2/L3: %.1f MB/%.1f MB", Cpu::l2() / 1024.0, Cpu::l3() / 1024.0); # endif } } @@ -100,28 +100,28 @@ static void print_threads() buf[0] = '\0'; } - Console::i()->text(Options::i()->colors() ? "\x1B[01;32m * \x1B[01;37mTHREADS: \x1B[01;36m%d\x1B[01;37m, %s, av=%d, donate=%d%%%s%s" : " * THREADS: %d, %s, av=%d, donate=%d%%%s%s", - Options::i()->threads(), - Options::i()->algoName(), - Options::i()->algoVariant(), - Options::i()->donateLevel(), - Options::i()->nicehash() ? ", nicehash" : "", buf); + Log::i()->text(Options::i()->colors() ? "\x1B[01;32m * \x1B[01;37mTHREADS: \x1B[01;36m%d\x1B[01;37m, %s, av=%d, donate=%d%%%s%s" : " * THREADS: %d, %s, av=%d, donate=%d%%%s%s", + Options::i()->threads(), + Options::i()->algoName(), + Options::i()->algoVariant(), + Options::i()->donateLevel(), + Options::i()->nicehash() ? ", nicehash" : "", buf); } static void print_pools() { - Console::i()->text(Options::i()->colors() ? "\x1B[01;32m * \x1B[01;37mPOOL #1: \x1B[01;36m%s:%d" : " * POOL #1: %s:%d", - Options::i()->url()->host(), - Options::i()->url()->port()); + Log::i()->text(Options::i()->colors() ? "\x1B[01;32m * \x1B[01;37mPOOL #1: \x1B[01;36m%s:%d" : " * POOL #1: %s:%d", + Options::i()->url()->host(), + Options::i()->url()->port()); if (!Options::i()->backupUrl()) { return; } - Console::i()->text(Options::i()->colors() ? "\x1B[01;32m * \x1B[01;37mPOOL #2: \x1B[01;36m%s:%d" : " * POOL #2: %s:%d", - Options::i()->backupUrl()->host(), - Options::i()->backupUrl()->port()); + Log::i()->text(Options::i()->colors() ? "\x1B[01;32m * \x1B[01;37mPOOL #2: \x1B[01;36m%s:%d" : " * POOL #2: %s:%d", + Options::i()->backupUrl()->host(), + Options::i()->backupUrl()->port()); } diff --git a/src/Console.cpp b/src/log/Log.cpp similarity index 90% rename from src/Console.cpp rename to src/log/Log.cpp index 8f160760..d4037f70 100644 --- a/src/Console.cpp +++ b/src/log/Log.cpp @@ -34,21 +34,21 @@ # include "3rdparty/winansi.h" #endif -#include "Console.h" +#include "log/Log.h" -Console *Console::m_self = nullptr; +Log *Log::m_self = nullptr; -void Console::init(bool colors, bool background) +void Log::init(bool colors, bool background) { if (!m_self) { - m_self = new Console(colors, background); + m_self = new Log(colors, background); } } -void Console::message(Console::Level level, const char* fmt, ...) +void Log::message(Log::Level level, const char* fmt, ...) { time_t now = time(nullptr); tm stime; @@ -113,7 +113,7 @@ void Console::message(Console::Level level, const char* fmt, ...) } -void Console::text(const char* fmt, ...) +void Log::text(const char* fmt, ...) { va_list ap; va_start(ap, fmt); @@ -134,7 +134,7 @@ void Console::text(const char* fmt, ...) } -Console::Console(bool colors, bool background) : +Log::Log(bool colors, bool background) : m_background(background), m_colors(colors) { diff --git a/src/Console.h b/src/log/Log.h similarity index 69% rename from src/Console.h rename to src/log/Log.h index 6e74aa46..7e1d0b04 100644 --- a/src/Console.h +++ b/src/log/Log.h @@ -21,14 +21,14 @@ * along with this program. If not, see . */ -#ifndef __CONSOLE_H__ -#define __CONSOLE_H__ +#ifndef __LOG_H__ +#define __LOG_H__ #include -class Console +class Log { public: enum Level { @@ -50,35 +50,35 @@ public: constexpr static const char* kCL_GRAY = "\x1B[90m"; # endif - static inline Console* i() { return m_self; } + static inline Log* i() { return m_self; } static void init(bool colors, bool background); void message(Level level, const char* fmt, ...); void text(const char* fmt, ...); private: - Console(bool colors, bool background); + Log(bool colors, bool background); bool m_background; bool m_colors; - static Console *m_self; + static Log *m_self; uv_mutex_t m_mutex; }; -#define LOG_ERR(x, ...) Console::i()->message(Console::ERR, x, ##__VA_ARGS__) -#define LOG_WARN(x, ...) Console::i()->message(Console::WARNING, x, ##__VA_ARGS__) -#define LOG_NOTICE(x, ...) Console::i()->message(Console::NOTICE, x, ##__VA_ARGS__) -#define LOG_INFO(x, ...) Console::i()->message(Console::INFO, x, ##__VA_ARGS__) +#define LOG_ERR(x, ...) Log::i()->message(Log::ERR, x, ##__VA_ARGS__) +#define LOG_WARN(x, ...) Log::i()->message(Log::WARNING, x, ##__VA_ARGS__) +#define LOG_NOTICE(x, ...) Log::i()->message(Log::NOTICE, x, ##__VA_ARGS__) +#define LOG_INFO(x, ...) Log::i()->message(Log::INFO, x, ##__VA_ARGS__) #ifdef APP_DEBUG -# define LOG_DEBUG(x, ...) Console::i()->message(Console::DEBUG, x, ##__VA_ARGS__) -# define LOG_DEBUG_ERR(x, ...) Console::i()->message(Console::ERR, x, ##__VA_ARGS__) -# define LOG_DEBUG_WARN(x, ...) Console::i()->message(Console::WARNING, x, ##__VA_ARGS__) +# define LOG_DEBUG(x, ...) Log::i()->message(Log::DEBUG, x, ##__VA_ARGS__) +# define LOG_DEBUG_ERR(x, ...) Log::i()->message(Log::ERR, x, ##__VA_ARGS__) +# define LOG_DEBUG_WARN(x, ...) Log::i()->message(Log::WARNING, x, ##__VA_ARGS__) #else # define LOG_DEBUG(x, ...) # define LOG_DEBUG_ERR(x, ...) # define LOG_DEBUG_WARN(x, ...) #endif -#endif /* __CONSOLE_H__ */ +#endif /* __LOG_H__ */ diff --git a/src/net/Client.cpp b/src/net/Client.cpp index 6fdcf331..8dd8051e 100644 --- a/src/net/Client.cpp +++ b/src/net/Client.cpp @@ -25,7 +25,7 @@ #include -#include "Console.h" +#include "log/Log.h" #include "interfaces/IClientListener.h" #include "net/Client.h" #include "net/JobResult.h" diff --git a/src/net/Job.cpp b/src/net/Job.cpp index 52123485..9934903f 100644 --- a/src/net/Job.cpp +++ b/src/net/Job.cpp @@ -23,11 +23,10 @@ #include -//#include +#include "log/Log.h" #include "net/Job.h" -#include "Console.h" static inline unsigned char hf_hex2bin(char c, bool &err) diff --git a/src/net/Network.cpp b/src/net/Network.cpp index 8a7ccc6b..8de785bd 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -25,7 +25,7 @@ #include -#include "Console.h" +#include "log/Log.h" #include "net/Client.h" #include "net/Network.h" #include "net/Url.h" diff --git a/src/workers/Hashrate.cpp b/src/workers/Hashrate.cpp index 694485cc..68139710 100644 --- a/src/workers/Hashrate.cpp +++ b/src/workers/Hashrate.cpp @@ -26,7 +26,7 @@ #include #include -#include "Console.h" +#include "log/Log.h" #include "Options.h" #include "workers/Hashrate.h" diff --git a/src/workers/Worker.cpp b/src/workers/Worker.cpp index 1cede65f..96cd4182 100644 --- a/src/workers/Worker.cpp +++ b/src/workers/Worker.cpp @@ -23,7 +23,6 @@ #include -#include "Console.h" #include "Cpu.h" #include "Mem.h" diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index 433bdcd8..f78d8e27 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -24,7 +24,6 @@ #include -#include "Console.h" #include "interfaces/IJobResultListener.h" #include "Mem.h" #include "Options.h"