added verbosity levels option

This commit is contained in:
Milad Nazari 2017-11-15 23:58:38 +01:00
parent d403dcf95c
commit f6bcba49c3
10 changed files with 50 additions and 23 deletions

View file

@ -69,18 +69,15 @@ App::App(int argc, char **argv) :
if (!m_options) {
return;
}
Log::init();
Log::init(m_options->verbosity());
if (!m_options->background()) {
Log::add(new ConsoleLog(m_options->colors()));
m_console = new Console(this);
}
if (m_options->logFile()) {
Log::add(new FileLog(m_options->logFile()));
}
# ifdef HAVE_SYSLOG_H
if (m_options->syslog()) {
Log::add(new SysLog());
@ -126,7 +123,12 @@ int App::exec()
}
Mem::allocate(m_options->algo(), m_options->threads(), m_options->doubleHash(), m_options->hugePages());
Summary::print();
if(m_options->verbosity() == 2) {
Summary::printVerbose();
}
else if(m_options->verbosity() == 1) {
Summary::print();
}
# ifndef XMRIG_NO_API
Api::start();
@ -138,7 +140,6 @@ int App::exec()
# endif
Workers::start(m_options->affinity(), m_options->priority());
m_network->connect();
const int r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);

View file

@ -53,7 +53,6 @@ private:
void close();
static void onSignal(uv_signal_t *handle, int signum);
static App *m_self;
Console *m_console;

View file

@ -62,6 +62,7 @@ Options:\n\
-p, --pass=PASSWORD password for mining server\n\
-t, --threads=N number of miner threads\n\
-v, --av=N algorithm variation, 0 auto select\n\
-b, --verbosity=N verbosity level of logs (0-2), 2 auto select\n\
-k, --keepalive send keepalived for prevent timeout (need pool support)\n\
-r, --retries=N number of times to retry before switch to backup server (default: 5)\n\
-R, --retry-pause=N time to pause between retries (default: 5)\n\
@ -91,12 +92,13 @@ Options:\n\
";
static char const short_options[] = "a:c:khBp:Px:r:R:s:t:T:o:u:O:v:Vl:S";
static char const short_options[] = "a:b:c:khBp:Px:r:R:s:t:T:o:u:O:v:Vl:S";
static struct option const options[] = {
{ "algo", 1, nullptr, 'a' },
{ "av", 1, nullptr, 'v' },
{ "verbosity", 1, nullptr, 'b' },
{ "background", 0, nullptr, 'B' },
{ "config", 1, nullptr, 'c' },
{ "cpu-affinity", 1, nullptr, 1020 },
@ -131,6 +133,7 @@ static struct option const options[] = {
static struct option const config_options[] = {
{ "algo", 1, nullptr, 'a' },
{ "av", 1, nullptr, 'v' },
{ "verbosity", 1, nullptr, 'b' },
{ "background", 0, nullptr, 'B' },
{ "colors", 0, nullptr, 2000 },
{ "cpu-affinity", 1, nullptr, 1020 },
@ -210,6 +213,7 @@ Options::Options(int argc, char **argv) :
m_userAgent(nullptr),
m_algo(0),
m_algoVariant(0),
m_verbosity(2),
m_apiPort(0),
m_donateLevel(kDonateLevel),
m_maxCpuUsage(75),
@ -367,6 +371,7 @@ bool Options::parseArg(int key, const char *arg)
case 'r': /* --retries */
case 'R': /* --retry-pause */
case 'v': /* --av */
case 'b': /* --verbosity */
case 1003: /* --donate-level */
case 1004: /* --max-cpu-usage */
case 1007: /* --print-time */
@ -414,7 +419,7 @@ bool Options::parseArg(int key, const char *arg)
free(m_userAgent);
m_userAgent = strdup(arg);
break;
default:
showUsage(1);
return false;
@ -462,6 +467,15 @@ bool Options::parseArg(int key, uint64_t arg)
m_algoVariant = (int) arg;
break;
case 'b': /* --verbosity */
if(arg < 0 || arg > 2) {
showUsage(1);
return false;
}
m_verbosity = (int) arg;
break;
case 1003: /* --donate-level */
if (arg < 1 || arg > 99) {

View file

@ -68,6 +68,7 @@ public:
inline const std::vector<Url*> &pools() const { return m_pools; }
inline int algo() const { return m_algo; }
inline int algoVariant() const { return m_algoVariant; }
inline int verbosity() const { return m_verbosity; }
inline int apiPort() const { return m_apiPort; }
inline int donateLevel() const { return m_donateLevel; }
inline int printTime() const { return m_printTime; }
@ -127,6 +128,7 @@ private:
int m_retries;
int m_retryPause;
int m_threads;
int m_verbosity;
int64_t m_affinity;
std::vector<Url*> m_pools;
};

View file

@ -34,7 +34,6 @@
#include "Summary.h"
#include "version.h"
static void print_versions()
{
char buf[16];
@ -158,6 +157,19 @@ void Summary::print()
print_threads();
print_pools();
# ifndef XMRIG_NO_API
print_api();
# endif
}
void Summary::printVerbose()
{
print_versions();
print_memory();
print_cpu();
print_threads();
print_pools();
# ifndef XMRIG_NO_API
print_api();
# endif

View file

@ -29,6 +29,7 @@ class Summary
{
public:
static void print();
static void printVerbose();
};

View file

@ -62,7 +62,6 @@ ConsoleLog::ConsoleLog(bool colors) :
# endif
}
void ConsoleLog::message(int level, const char* fmt, va_list args)
{
if (!isWritable()) {
@ -113,7 +112,7 @@ void ConsoleLog::message(int level, const char* fmt, va_list args)
m_colors ? color : "",
fmt,
m_colors ? Log::kCL_N : ""
);
);
print(args);
}

View file

@ -27,9 +27,8 @@
#include <uv.h>
#include "interfaces/ILogBackend.h"
#include "App.h"
class ConsoleLog : public ILogBackend
{

View file

@ -35,17 +35,17 @@
Log *Log::m_self = nullptr;
void Log::message(Log::Level level, const char* fmt, ...)
{
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);
if(verbosity == 2) {
for (ILogBackend *backend : m_backends) {
va_copy(copy, args);
backend->message(level, fmt, copy);
va_end(copy);
}
}
}
@ -65,7 +65,6 @@ void Log::text(const char* fmt, ...)
va_end(args);
}
Log::~Log()
{
for (auto backend : m_backends) {

View file

@ -56,18 +56,19 @@ public:
static inline Log* i() { return m_self; }
static inline void add(ILogBackend *backend) { i()->m_backends.push_back(backend); }
static inline void init() { if (!m_self) { m_self = new Log();} }
static inline void init(int verbosityL) { if (!m_self) {m_self = new Log(verbosityL);}}
static inline void release() { delete m_self; }
void message(Level level, const char* fmt, ...);
void text(const char* fmt, ...);
private:
inline Log() {}
inline Log(int verbosityL): verbosity(verbosityL) {}
~Log();
static Log *m_self;
std::vector<ILogBackend*> m_backends;
int verbosity;
};