mirror of
https://github.com/xmrig/xmrig.git
synced 2024-12-23 12:09:22 +00:00
#200 Use fprintf failback when fail to use uv_tty.
This commit is contained in:
parent
1961dcf824
commit
989c217b3f
2 changed files with 11 additions and 9 deletions
|
@ -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; }
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue