From 7447486cb01672e415db8f75f6264963a4de7fed Mon Sep 17 00:00:00 2001 From: Gregory Sanders Date: Mon, 6 Feb 2017 15:02:13 -0500 Subject: [PATCH] Don't redirect audit.log output with -printtoconsole --- src/util.cpp | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/src/util.cpp b/src/util.cpp index 5978fa68cf..07634726f6 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -373,35 +373,25 @@ int AuditLogPrintStr(const std::string &str) string strTimestamped = LogTimestampStr(str, &fStartedNewLine); - if (fPrintToConsole) - { - // print to console - ret = fwrite(strTimestamped.data(), 1, strTimestamped.size(), stdout); - fflush(stdout); + boost::call_once(&AuditPrintInit, auditPrintInitFlag); + boost::mutex::scoped_lock scoped_lock(*mutexAuditLog); + + // buffer if we haven't opened the log yet + if (fileout_audit == NULL) { + assert(vMsgsBeforeOpenAuditLog); + ret = strTimestamped.length(); + vMsgsBeforeOpenAuditLog->push_back(strTimestamped); } - else if (fPrintToAuditLog) + else { - boost::call_once(&AuditPrintInit, auditPrintInitFlag); - boost::mutex::scoped_lock scoped_lock(*mutexAuditLog); - - // buffer if we haven't opened the log yet - if (fileout_audit == NULL) { - assert(vMsgsBeforeOpenAuditLog); - ret = strTimestamped.length(); - vMsgsBeforeOpenAuditLog->push_back(strTimestamped); - } - else - { - // reopen the log file, if requested - if (fReopenAuditLog) { - fReopenAuditLog = false; - boost::filesystem::path pathAudit = GetDataDir() / "audit.log"; - if (freopen(pathAudit.string().c_str(),"a",fileout_audit) != NULL) - setbuf(fileout_audit, NULL); // unbuffered - } - - ret = FileWriteStr(strTimestamped, fileout_audit); + // reopen the log file, if requested + if (fReopenAuditLog) { + fReopenAuditLog = false; + boost::filesystem::path pathAudit = GetDataDir() / "audit.log"; + if (freopen(pathAudit.string().c_str(),"a",fileout_audit) != NULL) + setbuf(fileout_audit, NULL); // unbuffered } + ret = FileWriteStr(strTimestamped, fileout_audit); } return ret; }