Skip to content

Commit 0bd4cd3

Browse files
logging: remove unused return value from LogPrintStr
`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
1 parent 76f344d commit 0bd4cd3

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

src/logging.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,23 +198,20 @@ std::string BCLog::Logger::LogTimestampStr(const std::string &str)
198198
return strStamped;
199199
}
200200

201-
int BCLog::Logger::LogPrintStr(const std::string &str)
201+
void BCLog::Logger::LogPrintStr(const std::string &str)
202202
{
203-
int ret = 0; // Returns total number of characters written
204-
205203
std::string strTimestamped = LogTimestampStr(str);
206204

207205
if (m_print_to_console) {
208206
// print to console
209-
ret = fwrite(strTimestamped.data(), 1, strTimestamped.size(), stdout);
207+
fwrite(strTimestamped.data(), 1, strTimestamped.size(), stdout);
210208
fflush(stdout);
211209
}
212210
if (m_print_to_file) {
213211
std::lock_guard<std::mutex> scoped_lock(m_file_mutex);
214212

215213
// buffer if we haven't opened the log yet
216214
if (m_fileout == nullptr) {
217-
ret = strTimestamped.length();
218215
m_msgs_before_open.push_back(strTimestamped);
219216
}
220217
else
@@ -224,15 +221,14 @@ int BCLog::Logger::LogPrintStr(const std::string &str)
224221
m_reopen_file = false;
225222
m_fileout = fsbridge::freopen(m_file_path, "a", m_fileout);
226223
if (!m_fileout) {
227-
return ret;
224+
return;
228225
}
229226
setbuf(m_fileout, nullptr); // unbuffered
230227
}
231228

232-
ret = FileWriteStr(strTimestamped, m_fileout);
229+
FileWriteStr(strTimestamped, m_fileout);
233230
}
234231
}
235-
return ret;
236232
}
237233

238234
void BCLog::Logger::ShrinkDebugFile()

src/logging.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ namespace BCLog {
8686
std::atomic<bool> m_reopen_file{false};
8787

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

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

0 commit comments

Comments
 (0)