From b5902fd0b75415d61a938db9ab06122e5c4c3a12 Mon Sep 17 00:00:00 2001 From: fireice-uk Date: Wed, 22 Feb 2017 22:41:00 +0000 Subject: File logging option --- console.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'console.cpp') diff --git a/console.cpp b/console.cpp index 00c31c9..6a2555b 100644 --- a/console.cpp +++ b/console.cpp @@ -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 lck(print_mutex); fputs(buf, stdout); + + if(logfile != nullptr) + { + fputs(buf, logfile); + fflush(logfile); + } } void printer::print_str(const char* str) { std::unique_lock lck(print_mutex); fputs(str, stdout); + + if(logfile != nullptr) + { + fputs(str, logfile); + fflush(logfile); + } } -- cgit v1.1