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
|
@ -93,7 +93,7 @@ void xmrig::CommonConfig::printAPI()
|
|||
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",
|
||||
"API BIND", isApiIPv6() ? "[::]" : "0.0.0.0", apiPort());
|
||||
# endif
|
||||
|
@ -118,7 +118,7 @@ void xmrig::CommonConfig::printVersions()
|
|||
snprintf(buf, sizeof buf, "MSVC/%d", MSVC_VERSION);
|
||||
# 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",
|
||||
"ABOUT", APP_NAME, APP_VERSION, buf);
|
||||
|
||||
|
@ -157,8 +157,8 @@ void xmrig::CommonConfig::printVersions()
|
|||
length += snprintf(buf + length, (sizeof buf) - length, "microhttpd/%s ", MHD_get_version());
|
||||
# endif
|
||||
|
||||
Log::i()->text(isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13slibuv/%s %s")
|
||||
: " * %-13slibuv/%s %s",
|
||||
Log::print(isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13slibuv/%s %s")
|
||||
: " * %-13slibuv/%s %s",
|
||||
"LIBS", uv_version_string(), buf);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,63 +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_ILOGBACKEND_H
|
||||
#define XMRIG_ILOGBACKEND_H
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class ILogBackend
|
||||
{
|
||||
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 void message(Level level, const char* fmt, va_list args) = 0;
|
||||
virtual void text(const char* fmt, va_list args) = 0;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif // XMRIG_ILOGBACKEND_H
|
|
@ -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,136 +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 "base/tools/Handle.h"
|
||||
#include "common/log/ConsoleLog.h"
|
||||
#include "common/log/Log.h"
|
||||
|
||||
|
||||
xmrig::ConsoleLog::ConsoleLog() :
|
||||
m_stream(nullptr)
|
||||
{
|
||||
m_tty = new uv_tty_t;
|
||||
|
||||
if (uv_tty_init(uv_default_loop(), m_tty, 1, 0) < 0) {
|
||||
Log::colors = false;
|
||||
return;
|
||||
}
|
||||
|
||||
uv_tty_set_mode(m_tty, UV_TTY_MODE_NORMAL);
|
||||
m_uvBuf.base = m_buf;
|
||||
m_stream = reinterpret_cast<uv_stream_t*>(m_tty);
|
||||
|
||||
# ifdef WIN32
|
||||
HANDLE handle = GetStdHandle(STD_INPUT_HANDLE);
|
||||
if (handle != INVALID_HANDLE_VALUE) {
|
||||
DWORD mode = 0;
|
||||
if (GetConsoleMode(handle, &mode)) {
|
||||
mode &= ~ENABLE_QUICK_EDIT_MODE;
|
||||
SetConsoleMode(handle, mode | ENABLE_EXTENDED_FLAGS);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
xmrig::ConsoleLog::~ConsoleLog()
|
||||
{
|
||||
Handle::close(m_tty);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::ConsoleLog::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, 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);
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::ConsoleLog::isWritable() const
|
||||
{
|
||||
if (!m_stream || uv_is_writable(m_stream) != 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const uv_handle_type type = uv_guess_handle(1);
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -1,63 +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_CONSOLELOG_H
|
||||
#define XMRIG_CONSOLELOG_H
|
||||
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
#include "common/interfaces/ILogBackend.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class ConsoleLog : public ILogBackend
|
||||
{
|
||||
public:
|
||||
ConsoleLog();
|
||||
~ConsoleLog() override;
|
||||
|
||||
protected:
|
||||
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];
|
||||
uv_buf_t m_uvBuf;
|
||||
uv_stream_t *m_stream;
|
||||
uv_tty_t *m_tty;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* XMRIG_CONSOLELOG_H */
|
|
@ -1,101 +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/log/FileLog.h"
|
||||
#include "common/log/Log.h"
|
||||
|
||||
|
||||
xmrig::FileLog::FileLog(const char *fileName)
|
||||
{
|
||||
uv_fs_t req;
|
||||
m_file = uv_fs_open(uv_default_loop(), &req, fileName, O_CREAT | O_APPEND | O_WRONLY, 0644, nullptr);
|
||||
uv_fs_req_cleanup(&req);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::FileLog::message(Level level, const char* fmt, va_list args)
|
||||
{
|
||||
if (m_file < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
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, Log::colors),
|
||||
fmt,
|
||||
Log::endl(Log::colors)
|
||||
);
|
||||
|
||||
char *buf = new char[kBufferSize];
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::FileLog::onWrite(uv_fs_t *req)
|
||||
{
|
||||
delete [] static_cast<char *>(req->data);
|
||||
|
||||
uv_fs_req_cleanup(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);
|
||||
}
|
|
@ -1,59 +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_FILELOG_H
|
||||
#define XMRIG_FILELOG_H
|
||||
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
#include "common/interfaces/ILogBackend.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class FileLog : public ILogBackend
|
||||
{
|
||||
public:
|
||||
FileLog(const char *fileName);
|
||||
|
||||
void message(Level level, const char* fmt, va_list args) override;
|
||||
void text(const char* fmt, va_list args) override;
|
||||
|
||||
private:
|
||||
static void onWrite(uv_fs_t *req);
|
||||
|
||||
void write(char *data, size_t size);
|
||||
|
||||
char m_fmt[256];
|
||||
int m_file;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* XMRIG_FILELOG_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/>.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_LOG_H
|
||||
#define XMRIG_LOG_H
|
||||
#ifndef XMRIG_LOG_LEGACY_H
|
||||
#define XMRIG_LOG_LEGACY_H
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
#include <uv.h>
|
||||
#include <vector>
|
||||
#include "base/io/log/Log.h"
|
||||
|
||||
|
||||
#include "common/interfaces/ILogBackend.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 */
|
||||
#endif /* XMRIG_LOG_LEGACY_H */
|
||||
|
|
|
@ -1,48 +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 <syslog.h>
|
||||
|
||||
|
||||
#include "common/log/SysLog.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
xmrig::SysLog::SysLog()
|
||||
{
|
||||
openlog(APP_ID, LOG_PID, LOG_USER);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::SysLog::message(Level level, const char *fmt, va_list args)
|
||||
{
|
||||
vsyslog(static_cast<int>(level), fmt, args);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::SysLog::text(const char *fmt, va_list args)
|
||||
{
|
||||
vsyslog(LOG_INFO, fmt, args);
|
||||
}
|
|
@ -1,48 +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_SYSLOG_H
|
||||
#define XMRIG_SYSLOG_H
|
||||
|
||||
|
||||
#include "common/interfaces/ILogBackend.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class SysLog : public ILogBackend
|
||||
{
|
||||
public:
|
||||
SysLog();
|
||||
|
||||
void message(Level level, const char *fmt, va_list args) override;
|
||||
void text(const char *fmt, va_list args) override;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* XMRIG_SYSLOG_H */
|
Loading…
Add table
Add a link
Reference in a new issue