File logging option

This commit is contained in:
fireice-uk
2017-02-22 22:41:00 +00:00
parent 8c5671d6e0
commit b5902fd0b7
6 changed files with 44 additions and 3 deletions
+3
View File
@@ -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;
+8
View File
@@ -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
View File
@@ -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);
}
}
+2
View File
@@ -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;
};
+10 -3
View File
@@ -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;
+2
View File
@@ -43,6 +43,8 @@ public:
uint64_t GetVerboseLevel();
uint64_t GetAutohashTime();
const char* GetOutputFile();
uint64_t GetCallTimeout();
uint64_t GetNetRetry();
uint64_t GetGiveUpLimit();