From 989c217b3f91889fd4299a0792b06d6dd65768ae Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 18 Nov 2017 14:07:04 +0300 Subject: [PATCH] #200 Use fprintf failback when fail to use uv_tty. --- src/Options.h | 1 + src/log/ConsoleLog.cpp | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Options.h b/src/Options.h index 06b86f38d..9070888f7 100644 --- a/src/Options.h +++ b/src/Options.h @@ -76,6 +76,7 @@ public: inline int retryPause() const { return m_retryPause; } inline int threads() const { return m_threads; } inline int64_t affinity() const { return m_affinity; } + inline void setColors(bool colors) { m_colors = colors; } inline static void release() { delete m_self; } diff --git a/src/log/ConsoleLog.cpp b/src/log/ConsoleLog.cpp index ef8516ebe..457338580 100644 --- a/src/log/ConsoleLog.cpp +++ b/src/log/ConsoleLog.cpp @@ -36,6 +36,7 @@ #include "log/ConsoleLog.h" #include "log/Log.h" +#include "Options.h" ConsoleLog::ConsoleLog(bool colors) : @@ -43,6 +44,8 @@ ConsoleLog::ConsoleLog(bool colors) : m_stream(nullptr) { if (uv_tty_init(uv_default_loop(), &m_tty, 1, 0) < 0) { + Options::i()->setColors(false); + m_colors = false; return; } @@ -65,10 +68,6 @@ ConsoleLog::ConsoleLog(bool colors) : void ConsoleLog::message(int level, const char* fmt, va_list args) { - if (!isWritable()) { - return; - } - time_t now = time(nullptr); tm stime; @@ -121,10 +120,6 @@ void ConsoleLog::message(int level, const char* fmt, va_list args) void ConsoleLog::text(const char* fmt, va_list args) { - if (!isWritable()) { - return; - } - snprintf(m_fmt, sizeof(m_fmt) - 1, "%s%s\n", fmt, m_colors ? Log::kCL_N : ""); print(args); @@ -149,5 +144,11 @@ void ConsoleLog::print(va_list args) return; } - uv_try_write(m_stream, &m_uvBuf, 1); + if (!isWritable()) { + fprintf(stdout, m_buf); + fflush(stdout); + } + else { + uv_try_write(m_stream, &m_uvBuf, 1); + } }