Changeset View
Changeset View
Standalone View
Standalone View
src/logging.cpp
Show First 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | while (!m_msgs_before_open.empty()) { | ||||
const std::string &s = m_msgs_before_open.front(); | const std::string &s = m_msgs_before_open.front(); | ||||
if (m_print_to_file) { | if (m_print_to_file) { | ||||
FileWriteStr(s, m_fileout); | FileWriteStr(s, m_fileout); | ||||
} | } | ||||
if (m_print_to_console) { | if (m_print_to_console) { | ||||
fwrite(s.data(), 1, s.size(), stdout); | fwrite(s.data(), 1, s.size(), stdout); | ||||
} | } | ||||
for (const auto &cb : m_print_callbacks) { | |||||
cb(s); | |||||
} | |||||
m_msgs_before_open.pop_front(); | m_msgs_before_open.pop_front(); | ||||
} | } | ||||
if (m_print_to_console) { | if (m_print_to_console) { | ||||
fflush(stdout); | fflush(stdout); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
void BCLog::Logger::DisconnectTestLogger() { | void BCLog::Logger::DisconnectTestLogger() { | ||||
std::lock_guard<std::mutex> scoped_lock(m_cs); | std::lock_guard<std::mutex> scoped_lock(m_cs); | ||||
m_buffering = true; | m_buffering = true; | ||||
if (m_fileout != nullptr) { | if (m_fileout != nullptr) { | ||||
fclose(m_fileout); | fclose(m_fileout); | ||||
} | } | ||||
m_fileout = nullptr; | m_fileout = nullptr; | ||||
m_print_callbacks.clear(); | |||||
} | } | ||||
struct CLogCategoryDesc { | struct CLogCategoryDesc { | ||||
BCLog::LogFlags flag; | BCLog::LogFlags flag; | ||||
std::string category; | std::string category; | ||||
}; | }; | ||||
const CLogCategoryDesc LogCategories[] = { | const CLogCategoryDesc LogCategories[] = { | ||||
▲ Show 20 Lines • Show All 121 Lines • ▼ Show 20 Lines | if (m_buffering) { | ||||
return; | return; | ||||
} | } | ||||
if (m_print_to_console) { | if (m_print_to_console) { | ||||
// Print to console. | // Print to console. | ||||
fwrite(str_prefixed.data(), 1, str_prefixed.size(), stdout); | fwrite(str_prefixed.data(), 1, str_prefixed.size(), stdout); | ||||
fflush(stdout); | fflush(stdout); | ||||
} | } | ||||
for (const auto &cb : m_print_callbacks) { | |||||
cb(str_prefixed); | |||||
} | |||||
if (m_print_to_file) { | if (m_print_to_file) { | ||||
assert(m_fileout != nullptr); | assert(m_fileout != nullptr); | ||||
// Reopen the log file, if requested. | // Reopen the log file, if requested. | ||||
if (m_reopen_file) { | if (m_reopen_file) { | ||||
m_reopen_file = false; | m_reopen_file = false; | ||||
FILE *new_fileout = fsbridge::fopen(m_file_path, "a"); | FILE *new_fileout = fsbridge::fopen(m_file_path, "a"); | ||||
if (new_fileout) { | if (new_fileout) { | ||||
▲ Show 20 Lines • Show All 90 Lines • Show Last 20 Lines |