Skip to content

Commit

Permalink
logging: remove unused return value from LogPrintStr
Browse files Browse the repository at this point in the history
`LogPrintStr` returns the number of characters printed. This number is
doubled if both logging to console and logging to file is enabled. As
the return value is never used, I've opted to remove it instead of try
to fix it.

Credit: @laanwj
  • Loading branch information
practicalswift committed May 2, 2018
1 parent 76f344d commit 0bd4cd3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
12 changes: 4 additions & 8 deletions src/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,23 +198,20 @@ std::string BCLog::Logger::LogTimestampStr(const std::string &str)
return strStamped;
}

int BCLog::Logger::LogPrintStr(const std::string &str)
void BCLog::Logger::LogPrintStr(const std::string &str)
{
int ret = 0; // Returns total number of characters written

std::string strTimestamped = LogTimestampStr(str);

if (m_print_to_console) {
// print to console
ret = fwrite(strTimestamped.data(), 1, strTimestamped.size(), stdout);
fwrite(strTimestamped.data(), 1, strTimestamped.size(), stdout);
fflush(stdout);
}
if (m_print_to_file) {
std::lock_guard<std::mutex> scoped_lock(m_file_mutex);

// buffer if we haven't opened the log yet
if (m_fileout == nullptr) {
ret = strTimestamped.length();
m_msgs_before_open.push_back(strTimestamped);
}
else
Expand All @@ -224,15 +221,14 @@ int BCLog::Logger::LogPrintStr(const std::string &str)
m_reopen_file = false;
m_fileout = fsbridge::freopen(m_file_path, "a", m_fileout);
if (!m_fileout) {
return ret;
return;
}
setbuf(m_fileout, nullptr); // unbuffered
}

ret = FileWriteStr(strTimestamped, m_fileout);
FileWriteStr(strTimestamped, m_fileout);
}
}
return ret;
}

void BCLog::Logger::ShrinkDebugFile()
Expand Down
2 changes: 1 addition & 1 deletion src/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ namespace BCLog {
std::atomic<bool> m_reopen_file{false};

/** Send a string to the log output */
int LogPrintStr(const std::string &str);
void LogPrintStr(const std::string &str);

/** Returns whether logs will be written to any output */
bool Enabled() const { return m_print_to_console || m_print_to_file; }
Expand Down

0 comments on commit 0bd4cd3

Please sign in to comment.