mirror of
https://github.com/xmrig/xmrig.git
synced 2025-12-25 13:42:54 -05:00
Update log.
This commit is contained in:
@@ -1,13 +1,7 @@
|
||||
/* 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-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2019 Spudz76 <https://github.com/Spudz76>
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 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
|
||||
@@ -31,6 +25,7 @@
|
||||
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <mutex>
|
||||
@@ -76,7 +71,7 @@ public:
|
||||
|
||||
inline ~LogPrivate()
|
||||
{
|
||||
for (ILogBackend *backend : m_backends) {
|
||||
for (auto backend : m_backends) {
|
||||
delete backend;
|
||||
}
|
||||
}
|
||||
@@ -96,7 +91,7 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
timestamp(level, size, offset);
|
||||
const uint64_t ts = timestamp(level, size, offset);
|
||||
color(level, size);
|
||||
|
||||
const int rc = vsnprintf(m_buf + size, sizeof (m_buf) - offset - 32, fmt, args);
|
||||
@@ -114,9 +109,9 @@ public:
|
||||
}
|
||||
|
||||
if (!m_backends.empty()) {
|
||||
for (ILogBackend *backend : m_backends) {
|
||||
backend->print(level, m_buf, offset, size, true);
|
||||
backend->print(level, txt.c_str(), offset ? (offset - 11) : 0, txt.size(), false);
|
||||
for (auto backend : m_backends) {
|
||||
backend->print(ts, level, m_buf, offset, size, true);
|
||||
backend->print(ts, level, txt.c_str(), offset ? (offset - 11) : 0, txt.size(), false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -127,14 +122,15 @@ public:
|
||||
|
||||
|
||||
private:
|
||||
inline void timestamp(Log::Level level, size_t &size, size_t &offset)
|
||||
inline uint64_t timestamp(Log::Level level, size_t &size, size_t &offset)
|
||||
{
|
||||
const uint64_t ms = Chrono::currentMSecsSinceEpoch();
|
||||
|
||||
if (level == Log::NONE) {
|
||||
return;
|
||||
return ms;
|
||||
}
|
||||
|
||||
const uint64_t ms = Chrono::currentMSecsSinceEpoch();
|
||||
time_t now = ms / 1000;
|
||||
time_t now = ms / 1000;
|
||||
tm stime{};
|
||||
|
||||
# ifdef _WIN32
|
||||
@@ -156,6 +152,8 @@ private:
|
||||
if (rc > 0) {
|
||||
size = offset = static_cast<size_t>(rc);
|
||||
}
|
||||
|
||||
return ms;
|
||||
}
|
||||
|
||||
|
||||
@@ -195,10 +193,10 @@ private:
|
||||
};
|
||||
|
||||
|
||||
bool Log::m_background = false;
|
||||
bool Log::m_colors = true;
|
||||
LogPrivate *Log::d = new LogPrivate();
|
||||
uint32_t Log::m_verbose = 0;
|
||||
bool Log::m_background = false;
|
||||
bool Log::m_colors = true;
|
||||
LogPrivate *Log::d = nullptr;
|
||||
uint32_t Log::m_verbose = 0;
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
@@ -207,6 +205,8 @@ uint32_t Log::m_verbose = 0;
|
||||
|
||||
void xmrig::Log::add(ILogBackend *backend)
|
||||
{
|
||||
assert(d != nullptr);
|
||||
|
||||
if (d) {
|
||||
d->add(backend);
|
||||
}
|
||||
@@ -220,6 +220,12 @@ void xmrig::Log::destroy()
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Log::init()
|
||||
{
|
||||
d = new LogPrivate();
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Log::print(const char *fmt, ...)
|
||||
{
|
||||
if (!d) {
|
||||
|
||||
Reference in New Issue
Block a user