Log subsystem rewritten, to handle both color and not color logs simultaneously and overall simplicity.
This commit is contained in:
parent
0a893c2172
commit
ced25c3fa0
22 changed files with 489 additions and 559 deletions
|
@ -33,10 +33,6 @@ set(HEADERS
|
||||||
src/common/interfaces/IConfigCreator.h
|
src/common/interfaces/IConfigCreator.h
|
||||||
src/common/interfaces/IControllerListener.h
|
src/common/interfaces/IControllerListener.h
|
||||||
src/common/interfaces/ICpuInfo.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/log/Log.h
|
||||||
src/common/Platform.h
|
src/common/Platform.h
|
||||||
src/common/utils/mm_malloc.h
|
src/common/utils/mm_malloc.h
|
||||||
|
@ -92,10 +88,6 @@ set(SOURCES
|
||||||
src/common/config/ConfigWatcher.cpp
|
src/common/config/ConfigWatcher.cpp
|
||||||
src/common/crypto/Algorithm.cpp
|
src/common/crypto/Algorithm.cpp
|
||||||
src/common/crypto/keccak.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/common/Platform.cpp
|
||||||
src/core/Config.cpp
|
src/core/Config.cpp
|
||||||
src/core/Controller.cpp
|
src/core/Controller.cpp
|
||||||
|
@ -189,12 +181,6 @@ include(cmake/OpenSSL.cmake)
|
||||||
include(cmake/asm.cmake)
|
include(cmake/asm.cmake)
|
||||||
include(cmake/cn-gpu.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)
|
if (NOT WITH_AEON)
|
||||||
add_definitions(/DXMRIG_NO_AEON)
|
add_definitions(/DXMRIG_NO_AEON)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -31,9 +31,9 @@
|
||||||
#include "api/Api.h"
|
#include "api/Api.h"
|
||||||
#include "App.h"
|
#include "App.h"
|
||||||
#include "base/io/Console.h"
|
#include "base/io/Console.h"
|
||||||
|
#include "base/io/log/Log.h"
|
||||||
#include "base/kernel/Signals.h"
|
#include "base/kernel/Signals.h"
|
||||||
#include "common/cpu/Cpu.h"
|
#include "common/cpu/Cpu.h"
|
||||||
#include "common/log/Log.h"
|
|
||||||
#include "common/Platform.h"
|
#include "common/Platform.h"
|
||||||
#include "core/Config.h"
|
#include "core/Config.h"
|
||||||
#include "core/Controller.h"
|
#include "core/Controller.h"
|
||||||
|
@ -135,7 +135,7 @@ void xmrig::App::onConsoleCommand(char command)
|
||||||
case 'p':
|
case 'p':
|
||||||
case 'P':
|
case 'P':
|
||||||
if (Workers::isEnabled()) {
|
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);
|
Workers::setEnabled(false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -143,7 +143,7 @@ void xmrig::App::onConsoleCommand(char command)
|
||||||
case 'r':
|
case 'r':
|
||||||
case 'R':
|
case 'R':
|
||||||
if (!Workers::isEnabled()) {
|
if (!Workers::isEnabled()) {
|
||||||
LOG_INFO(m_controller->config()->isColors() ? "\x1B[01;32mresumed" : "resumed");
|
LOG_INFO(GREEN_BOLD("resumed"));
|
||||||
Workers::setEnabled(true);
|
Workers::setEnabled(true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -194,5 +194,5 @@ void xmrig::App::close()
|
||||||
m_controller->stop();
|
m_controller->stop();
|
||||||
|
|
||||||
Workers::stop();
|
Workers::stop();
|
||||||
Log::release();
|
Log::destroy();
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,11 +59,11 @@ inline static const char *asmName(xmrig::Assembly assembly, bool colors)
|
||||||
static void print_memory(xmrig::Config *config) {
|
static void print_memory(xmrig::Config *config) {
|
||||||
# ifdef _WIN32
|
# ifdef _WIN32
|
||||||
if (config->isColors()) {
|
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");
|
"HUGE PAGES", Mem::isHugepagesAvailable() ? "\x1B[1;32mavailable" : "\x1B[01;31munavailable");
|
||||||
}
|
}
|
||||||
else {
|
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
|
# endif
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ static void print_cpu(xmrig::Config *config)
|
||||||
using namespace xmrig;
|
using namespace xmrig;
|
||||||
|
|
||||||
if (config->isColors()) {
|
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",
|
||||||
Cpu::info()->brand(),
|
Cpu::info()->brand(),
|
||||||
Cpu::info()->sockets(),
|
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()->hasAES() ? "\x1B[1;32m" : "\x1B[1;31m-",
|
||||||
Cpu::info()->hasAVX2() ? "\x1B[1;32m" : "\x1B[1;31m-");
|
Cpu::info()->hasAVX2() ? "\x1B[1;32m" : "\x1B[1;31m-");
|
||||||
# ifndef XMRIG_NO_LIBCPUID
|
# 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
|
# endif
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Log::i()->text(" * %-13s%s (%d) %sx64 %sAES %sAVX2",
|
Log::print(" * %-13s%s (%d) %sx64 %sAES %sAVX2",
|
||||||
"CPU",
|
"CPU",
|
||||||
Cpu::info()->brand(),
|
Cpu::info()->brand(),
|
||||||
Cpu::info()->sockets(),
|
Cpu::info()->sockets(),
|
||||||
|
@ -94,7 +94,7 @@ static void print_cpu(xmrig::Config *config)
|
||||||
Cpu::info()->hasAES() ? "" : "-",
|
Cpu::info()->hasAES() ? "" : "-",
|
||||||
Cpu::info()->hasAVX2() ? "" : "-");
|
Cpu::info()->hasAVX2() ? "" : "-");
|
||||||
# ifndef XMRIG_NO_LIBCPUID
|
# 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
|
# endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ static void print_threads(xmrig::Config *config)
|
||||||
snprintf(buf, sizeof buf, ", affinity=0x%" PRIX64, config->affinity());
|
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",
|
: " * %-13s%d, %s, av=%d, %sdonate=%d%%%s",
|
||||||
"THREADS",
|
"THREADS",
|
||||||
config->threadsCount(),
|
config->threadsCount(),
|
||||||
|
@ -119,7 +119,7 @@ static void print_threads(xmrig::Config *config)
|
||||||
buf);
|
buf);
|
||||||
}
|
}
|
||||||
else {
|
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%%",
|
: " * %-13s%d, %s, %sdonate=%d%%",
|
||||||
"THREADS",
|
"THREADS",
|
||||||
config->threadsCount(),
|
config->threadsCount(),
|
||||||
|
@ -132,11 +132,11 @@ static void print_threads(xmrig::Config *config)
|
||||||
if (config->assembly() == xmrig::ASM_AUTO) {
|
if (config->assembly() == xmrig::ASM_AUTO) {
|
||||||
const xmrig::Assembly assembly = xmrig::Cpu::info()->assembly();
|
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()));
|
: " * %-13sauto:%s", "ASSEMBLY", asmName(assembly, config->isColors()));
|
||||||
}
|
}
|
||||||
else {
|
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
|
# endif
|
||||||
}
|
}
|
||||||
|
@ -145,12 +145,12 @@ static void print_threads(xmrig::Config *config)
|
||||||
static void print_commands(xmrig::Config *config)
|
static void print_commands(xmrig::Config *config)
|
||||||
{
|
{
|
||||||
if (config->isColors()) {
|
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("p") WHITE_BOLD("ause, ")
|
||||||
MAGENTA_BOLD("r") WHITE_BOLD("esume"));
|
MAGENTA_BOLD("r") WHITE_BOLD("esume"));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
xmrig::Log::i()->text(" * COMMANDS 'h' hashrate, 'p' pause, 'r' resume");
|
xmrig::Log::print(" * COMMANDS 'h' hashrate, 'p' pause, 'r' resume");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
set(HEADERS_BASE
|
set(HEADERS_BASE
|
||||||
src/base/io/Console.h
|
src/base/io/Console.h
|
||||||
src/base/io/Json.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/io/Watcher.h
|
||||||
src/base/kernel/Entry.h
|
src/base/kernel/Entry.h
|
||||||
src/base/kernel/interfaces/IClientListener.h
|
src/base/kernel/interfaces/IClientListener.h
|
||||||
|
@ -8,6 +11,7 @@ set(HEADERS_BASE
|
||||||
src/base/kernel/interfaces/IConsoleListener.h
|
src/base/kernel/interfaces/IConsoleListener.h
|
||||||
src/base/kernel/interfaces/IDnsListener.h
|
src/base/kernel/interfaces/IDnsListener.h
|
||||||
src/base/kernel/interfaces/ILineListener.h
|
src/base/kernel/interfaces/ILineListener.h
|
||||||
|
src/base/kernel/interfaces/ILogBackend.h
|
||||||
src/base/kernel/interfaces/ISignalListener.h
|
src/base/kernel/interfaces/ISignalListener.h
|
||||||
src/base/kernel/interfaces/IStrategy.h
|
src/base/kernel/interfaces/IStrategy.h
|
||||||
src/base/kernel/interfaces/IStrategyListener.h
|
src/base/kernel/interfaces/IStrategyListener.h
|
||||||
|
@ -37,6 +41,9 @@ set(HEADERS_BASE
|
||||||
set(SOURCES_BASE
|
set(SOURCES_BASE
|
||||||
src/base/io/Console.cpp
|
src/base/io/Console.cpp
|
||||||
src/base/io/Json.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/io/Watcher.cpp
|
||||||
src/base/kernel/Entry.cpp
|
src/base/kernel/Entry.cpp
|
||||||
src/base/kernel/Process.cpp
|
src/base/kernel/Process.cpp
|
||||||
|
@ -61,3 +68,12 @@ if (WIN32)
|
||||||
else()
|
else()
|
||||||
set(SOURCES_OS src/base/io/Json_unix.cpp)
|
set(SOURCES_OS src/base/io/Json_unix.cpp)
|
||||||
endif()
|
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()
|
||||||
|
|
245
src/base/io/log/Log.cpp
Normal file
245
src/base/io/log/Log.cpp
Normal file
|
@ -0,0 +1,245 @@
|
||||||
|
/* XMRig
|
||||||
|
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||||
|
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||||
|
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||||
|
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||||
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||||
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
|
* Copyright 2019 Spudz76 <https://github.com/Spudz76>
|
||||||
|
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||||
|
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
# include <winsock2.h>
|
||||||
|
# include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <time.h>
|
||||||
|
#include <uv.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
|
#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<size_t>(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<size_t>(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<ILogBackend*> 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);
|
||||||
|
}
|
129
src/base/io/log/Log.h
Normal file
129
src/base/io/log/Log.h
Normal file
|
@ -0,0 +1,129 @@
|
||||||
|
/* XMRig
|
||||||
|
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||||
|
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||||
|
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||||
|
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||||
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||||
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
|
* Copyright 2019 Spudz76 <https://github.com/Spudz76>
|
||||||
|
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||||
|
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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 */
|
|
@ -5,6 +5,7 @@
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
|
* Copyright 2019 Spudz76 <https://github.com/Spudz76>
|
||||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
|
@ -23,21 +24,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
# include <winsock2.h>
|
|
||||||
# include <windows.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#include "base/tools/Handle.h"
|
#include "base/tools/Handle.h"
|
||||||
#include "common/log/ConsoleLog.h"
|
#include "base/io/log/backends/ConsoleLog.h"
|
||||||
#include "common/log/Log.h"
|
#include "base/io/log/Log.h"
|
||||||
|
|
||||||
|
|
||||||
xmrig::ConsoleLog::ConsoleLog() :
|
xmrig::ConsoleLog::ConsoleLog() :
|
||||||
|
@ -51,7 +43,6 @@ xmrig::ConsoleLog::ConsoleLog() :
|
||||||
}
|
}
|
||||||
|
|
||||||
uv_tty_set_mode(m_tty, UV_TTY_MODE_NORMAL);
|
uv_tty_set_mode(m_tty, UV_TTY_MODE_NORMAL);
|
||||||
m_uvBuf.base = m_buf;
|
|
||||||
m_stream = reinterpret_cast<uv_stream_t*>(m_tty);
|
m_stream = reinterpret_cast<uv_stream_t*>(m_tty);
|
||||||
|
|
||||||
# ifdef WIN32
|
# ifdef WIN32
|
||||||
|
@ -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);
|
if (Log::colors != colors) {
|
||||||
tm stime;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
# ifdef _WIN32
|
# ifdef _WIN32
|
||||||
localtime_s(&stime, &now);
|
uv_buf_t buf = uv_buf_init(const_cast<char *>(line), static_cast<unsigned int>(size));
|
||||||
# else
|
# else
|
||||||
localtime_r(&now, &stime);
|
uv_buf_t buf = uv_buf_init(const_cast<char *>(line), size);
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
snprintf(m_fmt, sizeof(m_fmt) - 1, "[%d-%02d-%02d %02d:%02d:%02d]%s %s%s",
|
if (!isWritable()) {
|
||||||
stime.tm_year + 1900,
|
fputs(line, stdout);
|
||||||
stime.tm_mon + 1,
|
fflush(stdout);
|
||||||
stime.tm_mday,
|
}
|
||||||
stime.tm_hour,
|
else {
|
||||||
stime.tm_min,
|
uv_try_write(m_stream, &buf, 1);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -117,20 +95,3 @@ bool xmrig::ConsoleLog::isWritable() const
|
||||||
const uv_handle_type type = uv_guess_handle(1);
|
const uv_handle_type type = uv_guess_handle(1);
|
||||||
return type == UV_TTY || type == UV_NAMED_PIPE;
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,6 +5,7 @@
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
|
* Copyright 2019 Spudz76 <https://github.com/Spudz76>
|
||||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
|
@ -26,10 +27,11 @@
|
||||||
#define XMRIG_CONSOLELOG_H
|
#define XMRIG_CONSOLELOG_H
|
||||||
|
|
||||||
|
|
||||||
#include <uv.h>
|
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 {
|
namespace xmrig {
|
||||||
|
@ -42,16 +44,11 @@ public:
|
||||||
~ConsoleLog() override;
|
~ConsoleLog() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void message(Level level, const char *fmt, va_list args) override;
|
void print(int level, const char *line, size_t offset, size_t size, bool colors) override;
|
||||||
void text(const char *fmt, va_list args) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool isWritable() const;
|
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_stream_t *m_stream;
|
||||||
uv_tty_t *m_tty;
|
uv_tty_t *m_tty;
|
||||||
};
|
};
|
|
@ -5,6 +5,7 @@
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
|
* Copyright 2019 Spudz76 <https://github.com/Spudz76>
|
||||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
|
@ -23,15 +24,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <uv.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
|
|
||||||
#include "common/log/FileLog.h"
|
#include "base/io/log/backends/FileLog.h"
|
||||||
#include "common/log/Log.h"
|
|
||||||
|
|
||||||
|
|
||||||
xmrig::FileLog::FileLog(const char *fileName)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t now = time(nullptr);
|
|
||||||
tm stime;
|
|
||||||
|
|
||||||
# ifdef _WIN32
|
# ifdef _WIN32
|
||||||
localtime_s(&stime, &now);
|
uv_buf_t buf = uv_buf_init(strdup(line), static_cast<unsigned int>(size));
|
||||||
# else
|
# else
|
||||||
localtime_r(&now, &stime);
|
uv_buf_t buf = uv_buf_init(strdup(line), size);
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
snprintf(m_fmt, sizeof(m_fmt) - 1, "[%d-%02d-%02d %02d:%02d:%02d]%s %s%s",
|
uv_fs_t *req = new uv_fs_t;
|
||||||
stime.tm_year + 1900,
|
req->data = buf.base;
|
||||||
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)
|
|
||||||
);
|
|
||||||
|
|
||||||
char *buf = new char[kBufferSize];
|
uv_fs_write(uv_default_loop(), req, m_file, &buf, 1, -1, FileLog::onWrite);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -89,13 +64,3 @@ void xmrig::FileLog::onWrite(uv_fs_t *req)
|
||||||
uv_fs_req_cleanup(req);
|
uv_fs_req_cleanup(req);
|
||||||
delete 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);
|
|
||||||
}
|
|
|
@ -5,6 +5,7 @@
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
|
* Copyright 2019 Spudz76 <https://github.com/Spudz76>
|
||||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
|
@ -26,10 +27,10 @@
|
||||||
#define XMRIG_FILELOG_H
|
#define XMRIG_FILELOG_H
|
||||||
|
|
||||||
|
|
||||||
#include <uv.h>
|
typedef struct uv_fs_s uv_fs_t;
|
||||||
|
|
||||||
|
|
||||||
#include "common/interfaces/ILogBackend.h"
|
#include "base/kernel/interfaces/ILogBackend.h"
|
||||||
|
|
||||||
|
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
@ -40,15 +41,13 @@ class FileLog : public ILogBackend
|
||||||
public:
|
public:
|
||||||
FileLog(const char *fileName);
|
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:
|
private:
|
||||||
static void onWrite(uv_fs_t *req);
|
static void onWrite(uv_fs_t *req);
|
||||||
|
|
||||||
void write(char *data, size_t size);
|
|
||||||
|
|
||||||
char m_fmt[256];
|
|
||||||
int m_file;
|
int m_file;
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
|
* Copyright 2019 Spudz76 <https://github.com/Spudz76>
|
||||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
|
@ -26,7 +27,7 @@
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
|
||||||
|
|
||||||
#include "common/log/SysLog.h"
|
#include "base/io/log/backends/SysLog.h"
|
||||||
#include "version.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<int>(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);
|
||||||
}
|
}
|
|
@ -5,6 +5,7 @@
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
|
* Copyright 2019 Spudz76 <https://github.com/Spudz76>
|
||||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
|
@ -26,7 +27,7 @@
|
||||||
#define XMRIG_SYSLOG_H
|
#define XMRIG_SYSLOG_H
|
||||||
|
|
||||||
|
|
||||||
#include "common/interfaces/ILogBackend.h"
|
#include "base/kernel/interfaces/ILogBackend.h"
|
||||||
|
|
||||||
|
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
@ -36,9 +37,10 @@ class SysLog : public ILogBackend
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SysLog();
|
SysLog();
|
||||||
|
~SysLog();
|
||||||
|
|
||||||
void message(Level level, const char *fmt, va_list args) override;
|
protected:
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
|
* Copyright 2019 Spudz76 <https://github.com/Spudz76>
|
||||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
|
@ -36,24 +37,9 @@ namespace xmrig {
|
||||||
class ILogBackend
|
class ILogBackend
|
||||||
{
|
{
|
||||||
public:
|
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 ~ILogBackend() = default;
|
||||||
|
|
||||||
virtual void message(Level level, const char* fmt, va_list args) = 0;
|
virtual void print(int level, const char *line, size_t offset, size_t size, bool colors) = 0;
|
||||||
virtual void text(const char* fmt, va_list args) = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -164,7 +164,7 @@ void xmrig::Pools::print() const
|
||||||
if (Log::colors) {
|
if (Log::colors) {
|
||||||
const int color = pool.isEnabled() ? (pool.isTLS() ? 32 : 36) : 31;
|
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"),
|
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("POOL #%-7zu") "\x1B[1;%dm%s\x1B[0m variant " WHITE_BOLD("%s"),
|
||||||
i,
|
i,
|
||||||
color,
|
color,
|
||||||
pool.url().data(),
|
pool.url().data(),
|
||||||
|
@ -172,7 +172,7 @@ void xmrig::Pools::print() const
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Log::i()->text(" * POOL #%-7zu%s%s variant=%s %s",
|
Log::print(" * POOL #%-7zu%s%s variant=%s %s",
|
||||||
i,
|
i,
|
||||||
pool.isEnabled() ? "" : "-",
|
pool.isEnabled() ? "" : "-",
|
||||||
pool.url().data(),
|
pool.url().data(),
|
||||||
|
|
|
@ -93,7 +93,7 @@ void xmrig::CommonConfig::printAPI()
|
||||||
return;
|
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",
|
: " * %-13s%s:%d",
|
||||||
"API BIND", isApiIPv6() ? "[::]" : "0.0.0.0", apiPort());
|
"API BIND", isApiIPv6() ? "[::]" : "0.0.0.0", apiPort());
|
||||||
# endif
|
# endif
|
||||||
|
@ -118,7 +118,7 @@ void xmrig::CommonConfig::printVersions()
|
||||||
snprintf(buf, sizeof buf, "MSVC/%d", MSVC_VERSION);
|
snprintf(buf, sizeof buf, "MSVC/%d", MSVC_VERSION);
|
||||||
# endif
|
# 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",
|
: " * %-13s%s/%s %s",
|
||||||
"ABOUT", APP_NAME, APP_VERSION, buf);
|
"ABOUT", APP_NAME, APP_VERSION, buf);
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ void xmrig::CommonConfig::printVersions()
|
||||||
length += snprintf(buf + length, (sizeof buf) - length, "microhttpd/%s ", MHD_get_version());
|
length += snprintf(buf + length, (sizeof buf) - length, "microhttpd/%s ", MHD_get_version());
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
Log::i()->text(isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13slibuv/%s %s")
|
Log::print(isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13slibuv/%s %s")
|
||||||
: " * %-13slibuv/%s %s",
|
: " * %-13slibuv/%s %s",
|
||||||
"LIBS", uv_version_string(), buf);
|
"LIBS", uv_version_string(), buf);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,90 +0,0 @@
|
||||||
/* XMRig
|
|
||||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
|
||||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
|
||||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
|
||||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
|
||||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
# include <winsock2.h>
|
|
||||||
# include <windows.h>
|
|
||||||
#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);
|
|
||||||
}
|
|
|
@ -1,57 +0,0 @@
|
||||||
/* XMRig
|
|
||||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
|
||||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
|
||||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
|
||||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
|
||||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef XMRIG_BASICLOG_H
|
|
||||||
#define XMRIG_BASICLOG_H
|
|
||||||
|
|
||||||
|
|
||||||
#include <uv.h>
|
|
||||||
|
|
||||||
|
|
||||||
#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 */
|
|
|
@ -1,134 +0,0 @@
|
||||||
/* XMRig
|
|
||||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
|
||||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
|
||||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
|
||||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
|
||||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
|
|
||||||
#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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -22,90 +22,11 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef XMRIG_LOG_H
|
#ifndef XMRIG_LOG_LEGACY_H
|
||||||
#define XMRIG_LOG_H
|
#define XMRIG_LOG_LEGACY_H
|
||||||
|
|
||||||
|
|
||||||
#include <assert.h>
|
#include "base/io/log/Log.h"
|
||||||
#include <uv.h>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
|
|
||||||
#include "common/interfaces/ILogBackend.h"
|
#endif /* XMRIG_LOG_LEGACY_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<ILogBackend*> 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 */
|
|
||||||
|
|
|
@ -26,11 +26,11 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include "base/io/log/backends/ConsoleLog.h"
|
||||||
|
#include "base/io/log/backends/FileLog.h"
|
||||||
#include "common/config/ConfigLoader.h"
|
#include "common/config/ConfigLoader.h"
|
||||||
#include "common/cpu/Cpu.h"
|
#include "common/cpu/Cpu.h"
|
||||||
#include "common/interfaces/IControllerListener.h"
|
#include "common/interfaces/IControllerListener.h"
|
||||||
#include "common/log/ConsoleLog.h"
|
|
||||||
#include "common/log/FileLog.h"
|
|
||||||
#include "common/log/Log.h"
|
#include "common/log/Log.h"
|
||||||
#include "common/Platform.h"
|
#include "common/Platform.h"
|
||||||
#include "core/Config.h"
|
#include "core/Config.h"
|
||||||
|
@ -39,7 +39,7 @@
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_SYSLOG_H
|
#ifdef HAVE_SYSLOG_H
|
||||||
# include "common/log/SysLog.h"
|
# include "base/io/log/backends/SysLog.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -102,7 +102,6 @@ int xmrig::Controller::init()
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::init();
|
|
||||||
Platform::init(config()->userAgent());
|
Platform::init(config()->userAgent());
|
||||||
Platform::setProcessPriority(d_ptr->config->priority());
|
Platform::setProcessPriority(d_ptr->config->priority());
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
#define APP_ID "xmrig"
|
#define APP_ID "xmrig"
|
||||||
#define APP_NAME "XMRig"
|
#define APP_NAME "XMRig"
|
||||||
#define APP_DESC "XMRig CPU miner"
|
#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_DOMAIN "xmrig.com"
|
||||||
#define APP_SITE "www.xmrig.com"
|
#define APP_SITE "www.xmrig.com"
|
||||||
#define APP_COPYRIGHT "Copyright (C) 2016-2019 xmrig.com"
|
#define APP_COPYRIGHT "Copyright (C) 2016-2019 xmrig.com"
|
||||||
|
@ -36,7 +36,7 @@
|
||||||
|
|
||||||
#define APP_VER_MAJOR 2
|
#define APP_VER_MAJOR 2
|
||||||
#define APP_VER_MINOR 15
|
#define APP_VER_MINOR 15
|
||||||
#define APP_VER_PATCH 0
|
#define APP_VER_PATCH 1
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
# if (_MSC_VER >= 1910)
|
# if (_MSC_VER >= 1910)
|
||||||
|
|
|
@ -104,11 +104,11 @@ void Workers::printHashrate(bool detail)
|
||||||
char num2[8] = { 0 };
|
char num2[8] = { 0 };
|
||||||
char num3[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;
|
size_t i = 0;
|
||||||
for (const xmrig::IThread *thread : m_controller->config()->threads()) {
|
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->index(),
|
||||||
thread->affinity(),
|
thread->affinity(),
|
||||||
Hashrate::format(m_hashrate->calc(thread->index(), Hashrate::ShortInterval), num1, sizeof num1),
|
Hashrate::format(m_hashrate->calc(thread->index(), Hashrate::ShortInterval), num1, sizeof num1),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue