mirror of
https://github.com/jwinterm/xmr-stak.git
synced 2026-10-17 05:41:41 +02:00
File logging option
This commit is contained in:
@@ -124,6 +124,9 @@ int main(int argc, char *argv[])
|
||||
printer::inst()->print_str("'c' - connection\n");
|
||||
printer::inst()->print_str("-------------------------------------------------------------------\n");
|
||||
|
||||
if(strlen(jconf::inst()->GetOutputFile()) != 0)
|
||||
printer::inst()->open_logfile(jconf::inst()->GetOutputFile());
|
||||
|
||||
executor::inst()->ex_start();
|
||||
|
||||
int key;
|
||||
|
||||
@@ -140,6 +140,14 @@
|
||||
*/
|
||||
"h_print_time" : 60,
|
||||
|
||||
/*
|
||||
* Output file
|
||||
*
|
||||
* output_file - This option will log all output to a file.
|
||||
*
|
||||
*/
|
||||
"output_file" : "",
|
||||
|
||||
/*
|
||||
* Built-in web server
|
||||
* I like checking my hashrate on my phone. Don't you?
|
||||
|
||||
+19
@@ -155,6 +155,13 @@ printer* printer::oInst = nullptr;
|
||||
printer::printer()
|
||||
{
|
||||
verbose_level = LINF;
|
||||
logfile = nullptr;
|
||||
}
|
||||
|
||||
bool printer::open_logfile(const char* file)
|
||||
{
|
||||
logfile = fopen(file, "ab+");
|
||||
return logfile != nullptr;
|
||||
}
|
||||
|
||||
void printer::print_msg(verbosity verbose, const char* fmt, ...)
|
||||
@@ -185,10 +192,22 @@ void printer::print_msg(verbosity verbose, const char* fmt, ...)
|
||||
|
||||
std::unique_lock<std::mutex> lck(print_mutex);
|
||||
fputs(buf, stdout);
|
||||
|
||||
if(logfile != nullptr)
|
||||
{
|
||||
fputs(buf, logfile);
|
||||
fflush(logfile);
|
||||
}
|
||||
}
|
||||
|
||||
void printer::print_str(const char* str)
|
||||
{
|
||||
std::unique_lock<std::mutex> lck(print_mutex);
|
||||
fputs(str, stdout);
|
||||
|
||||
if(logfile != nullptr)
|
||||
{
|
||||
fputs(str, logfile);
|
||||
fflush(logfile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ public:
|
||||
inline void set_verbose_level(size_t level) { verbose_level = (verbosity)level; }
|
||||
void print_msg(verbosity verbose, const char* fmt, ...);
|
||||
void print_str(const char* str);
|
||||
bool open_logfile(const char* file);
|
||||
|
||||
private:
|
||||
printer();
|
||||
@@ -38,4 +39,5 @@ private:
|
||||
|
||||
std::mutex print_mutex;
|
||||
verbosity verbose_level;
|
||||
FILE* logfile;
|
||||
};
|
||||
|
||||
@@ -45,9 +45,10 @@ using namespace rapidjson;
|
||||
/*
|
||||
* This enum needs to match index in oConfigValues, otherwise we will get a runtime error
|
||||
*/
|
||||
enum configEnum { iCpuThreadNum, aCpuThreadsConf, sUseSlowMem, bNiceHashMode, bTlsMode, bTlsSecureAlgo, sTlsFingerprint,
|
||||
sPoolAddr, sWalletAddr, sPoolPwd, iCallTimeout, iNetRetry, iGiveUpLimit, iVerboseLevel, iAutohashTime, iHttpdPort,
|
||||
bPreferIpv4 };
|
||||
enum configEnum { iCpuThreadNum, aCpuThreadsConf, sUseSlowMem, bNiceHashMode,
|
||||
bTlsMode, bTlsSecureAlgo, sTlsFingerprint, sPoolAddr, sWalletAddr, sPoolPwd,
|
||||
iCallTimeout, iNetRetry, iGiveUpLimit, iVerboseLevel, iAutohashTime,
|
||||
sOutputFile, iHttpdPort, bPreferIpv4 };
|
||||
|
||||
struct configVal {
|
||||
configEnum iName;
|
||||
@@ -72,6 +73,7 @@ configVal oConfigValues[] = {
|
||||
{ iGiveUpLimit, "giveup_limit", kNumberType },
|
||||
{ iVerboseLevel, "verbose_level", kNumberType },
|
||||
{ iAutohashTime, "h_print_time", kNumberType },
|
||||
{ sOutputFile, "output_file", kStringType },
|
||||
{ iHttpdPort, "httpd_port", kNumberType },
|
||||
{ bPreferIpv4, "prefer_ipv4", kTrueType }
|
||||
};
|
||||
@@ -242,6 +244,11 @@ bool jconf::NiceHashMode()
|
||||
return prv->configValues[bNiceHashMode]->GetBool();
|
||||
}
|
||||
|
||||
const char* jconf::GetOutputFile()
|
||||
{
|
||||
return prv->configValues[sOutputFile]->GetString();
|
||||
}
|
||||
|
||||
bool jconf::check_cpu_features()
|
||||
{
|
||||
constexpr int AESNI_BIT = 1 << 25;
|
||||
|
||||
Reference in New Issue
Block a user