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
+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);
}
}