From 1c0da4513fba40db3a995860c3ba3ce4bd459099 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Wed, 27 Oct 2021 16:21:56 +0200 Subject: [PATCH] Added `--no-color` command line option `--no-color` disables colors in console output --- src/log.cpp | 9 ++++++++- src/log.h | 1 + src/main.cpp | 1 + src/params.cpp | 4 ++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/log.cpp b/src/log.cpp index 2f7fca2..9ea46ac 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -28,6 +28,7 @@ namespace p2pool { namespace log { int GLOBAL_LOG_LEVEL = 3; +bool CONSOLE_COLORS = true; #ifndef P2POOL_LOG_DISABLE @@ -159,6 +160,10 @@ private: p += 3; size -= 3; + if (!CONSOLE_COLORS) { + strip_colors(p, size); + } + #ifdef _WIN32 DWORD k; WriteConsole((severity == 1) ? hStdOut : hStdErr, p, size, &k, nullptr); @@ -176,7 +181,9 @@ private: } if (m_logFile.is_open()) { - strip_colors(p, size); + if (CONSOLE_COLORS) { + strip_colors(p, size); + } if (severity == 1) { m_logFile.write("NOTICE ", 8); diff --git a/src/log.h b/src/log.h index 0fe1963..8711884 100644 --- a/src/log.h +++ b/src/log.h @@ -22,6 +22,7 @@ namespace p2pool { namespace log { extern int GLOBAL_LOG_LEVEL; +extern bool CONSOLE_COLORS; constexpr int MAX_GLOBAL_LOG_LEVEL = 6; enum class Severity { diff --git a/src/main.cpp b/src/main.cpp index 0f61ec6..52a855c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -38,6 +38,7 @@ static void usage() "--data-api Path to the p2pool JSON data (use it in tandem with an external web-server)\n" "--stratum-api Enable /local/ path in api path for Stratum Server statistics\n" "--no-cache Disable p2pool.cache\n" + "--no-color Disable colors in console output\n" "--help Show this help message\n\n" "Example command line:\n\n" "%s --host 127.0.0.1 --rpc-port 18081 --zmq-port 18083 --wallet YOUR_WALLET_ADDRESS --stratum 0.0.0.0:%d --p2p 0.0.0.0:%d\n\n", diff --git a/src/params.cpp b/src/params.cpp index a017e14..6457391 100644 --- a/src/params.cpp +++ b/src/params.cpp @@ -77,6 +77,10 @@ Params::Params(int argc, char* argv[]) if (strcmp(argv[i], "--no-cache") == 0) { m_blockCache = false; } + + if (strcmp(argv[i], "--no-color") == 0) { + log::CONSOLE_COLORS = false; + } } if (m_stratumAddresses.empty()) {