2017-06-04 17:52:21 +00:00
|
|
|
/* 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>
|
2018-04-14 00:01:12 +00:00
|
|
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
|
|
|
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
2017-06-04 17:52:21 +00:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2017-06-20 10:04:38 +00:00
|
|
|
#ifndef __LOG_H__
|
|
|
|
#define __LOG_H__
|
2017-06-04 17:52:21 +00:00
|
|
|
|
|
|
|
|
2018-04-14 00:01:12 +00:00
|
|
|
#include <assert.h>
|
2017-06-12 13:19:07 +00:00
|
|
|
#include <uv.h>
|
2017-06-22 11:41:34 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
|
|
class ILogBackend;
|
2017-06-04 17:52:21 +00:00
|
|
|
|
|
|
|
|
2017-06-20 10:04:38 +00:00
|
|
|
class Log
|
2017-06-04 17:52:21 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum Level {
|
|
|
|
ERR,
|
|
|
|
WARNING,
|
|
|
|
NOTICE,
|
|
|
|
INFO,
|
|
|
|
DEBUG
|
|
|
|
};
|
|
|
|
|
|
|
|
constexpr static const char* kCL_N = "\x1B[0m";
|
|
|
|
constexpr static const char* kCL_RED = "\x1B[31m";
|
|
|
|
constexpr static const char* kCL_YELLOW = "\x1B[33m";
|
|
|
|
constexpr static const char* kCL_WHITE = "\x1B[01;37m";
|
|
|
|
|
|
|
|
# ifdef WIN32
|
|
|
|
constexpr static const char* kCL_GRAY = "\x1B[01;30m";
|
|
|
|
# else
|
|
|
|
constexpr static const char* kCL_GRAY = "\x1B[90m";
|
|
|
|
# endif
|
|
|
|
|
2018-04-14 00:01:12 +00:00
|
|
|
static inline Log* i() { assert(m_self != nullptr); return m_self; }
|
2017-06-22 11:41:34 +00:00
|
|
|
static inline void add(ILogBackend *backend) { i()->m_backends.push_back(backend); }
|
2018-04-14 00:01:12 +00:00
|
|
|
static inline void init() { if (!m_self) { new Log(); } }
|
|
|
|
static inline void release() { assert(m_self != nullptr); delete m_self; }
|
2017-06-04 17:52:21 +00:00
|
|
|
|
|
|
|
void message(Level level, const char* fmt, ...);
|
|
|
|
void text(const char* fmt, ...);
|
|
|
|
|
|
|
|
private:
|
2018-04-14 00:01:12 +00:00
|
|
|
inline Log() {
|
|
|
|
assert(m_self == nullptr);
|
|
|
|
|
|
|
|
uv_mutex_init(&m_mutex);
|
|
|
|
|
|
|
|
m_self = this;
|
|
|
|
}
|
|
|
|
|
2017-06-22 11:41:34 +00:00
|
|
|
~Log();
|
2017-06-04 17:52:21 +00:00
|
|
|
|
2017-06-20 10:04:38 +00:00
|
|
|
static Log *m_self;
|
2017-06-22 11:41:34 +00:00
|
|
|
std::vector<ILogBackend*> m_backends;
|
2018-04-14 00:01:12 +00:00
|
|
|
uv_mutex_t m_mutex;
|
2017-06-04 17:52:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-04-29 07:24:44 +00:00
|
|
|
#define RED_BOLD(x) "\e[1;31m" x "\e[0m"
|
|
|
|
#define RED(x) "\e[0;31m" x "\e[0m"
|
2018-04-23 06:20:43 +00:00
|
|
|
#define GREEN_BOLD(x) "\e[1;32m" x "\e[0m"
|
|
|
|
#define GREEN(x) "\e[0;32m" x "\e[0m"
|
2018-04-21 12:55:51 +00:00
|
|
|
#define MAGENTA_BOLD(x) "\e[1;35m" x "\e[0m"
|
|
|
|
#define MAGENTA(x) "\e[0;35m" x "\e[0m"
|
2018-04-23 06:20:43 +00:00
|
|
|
#define CYAN_BOLD(x) "\e[1;36m" x "\e[0m"
|
|
|
|
#define CYAN(x) "\e[0;36m" x "\e[0m"
|
2018-04-21 12:55:51 +00:00
|
|
|
#define WHITE_BOLD(x) "\e[1;37m" x "\e[0m"
|
|
|
|
#define WHITE(x) "\e[0;37m" x "\e[0m"
|
|
|
|
|
|
|
|
|
2017-06-20 10:04:38 +00:00
|
|
|
#define LOG_ERR(x, ...) Log::i()->message(Log::ERR, x, ##__VA_ARGS__)
|
|
|
|
#define LOG_WARN(x, ...) Log::i()->message(Log::WARNING, x, ##__VA_ARGS__)
|
|
|
|
#define LOG_NOTICE(x, ...) Log::i()->message(Log::NOTICE, x, ##__VA_ARGS__)
|
|
|
|
#define LOG_INFO(x, ...) Log::i()->message(Log::INFO, x, ##__VA_ARGS__)
|
2017-06-04 17:52:21 +00:00
|
|
|
|
|
|
|
#ifdef APP_DEBUG
|
2017-06-20 10:04:38 +00:00
|
|
|
# define LOG_DEBUG(x, ...) Log::i()->message(Log::DEBUG, x, ##__VA_ARGS__)
|
2017-08-14 05:41:54 +00:00
|
|
|
#else
|
|
|
|
# define LOG_DEBUG(x, ...)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(APP_DEBUG) || defined(APP_DEVEL)
|
2017-06-20 10:04:38 +00:00
|
|
|
# define LOG_DEBUG_ERR(x, ...) Log::i()->message(Log::ERR, x, ##__VA_ARGS__)
|
|
|
|
# define LOG_DEBUG_WARN(x, ...) Log::i()->message(Log::WARNING, x, ##__VA_ARGS__)
|
2017-06-04 17:52:21 +00:00
|
|
|
#else
|
|
|
|
# define LOG_DEBUG_ERR(x, ...)
|
2017-06-07 06:07:31 +00:00
|
|
|
# define LOG_DEBUG_WARN(x, ...)
|
2017-06-04 17:52:21 +00:00
|
|
|
#endif
|
|
|
|
|
2017-06-20 10:04:38 +00:00
|
|
|
#endif /* __LOG_H__ */
|