Changeset View
Changeset View
Standalone View
Standalone View
src/logging.cpp
Show All 31 Lines | BCLog::Logger &LogInstance() { | ||||
return *g_logger; | return *g_logger; | ||||
} | } | ||||
static int FileWriteStr(const std::string &str, FILE *fp) { | static int FileWriteStr(const std::string &str, FILE *fp) { | ||||
return fwrite(str.data(), 1, str.size(), fp); | return fwrite(str.data(), 1, str.size(), fp); | ||||
} | } | ||||
bool BCLog::Logger::StartLogging() { | bool BCLog::Logger::StartLogging() { | ||||
LockGuard scoped_lock(m_cs); | StdLockGuard scoped_lock(m_cs); | ||||
assert(m_buffering); | assert(m_buffering); | ||||
assert(m_fileout == nullptr); | assert(m_fileout == nullptr); | ||||
if (m_print_to_file) { | if (m_print_to_file) { | ||||
assert(!m_file_path.empty()); | assert(!m_file_path.empty()); | ||||
m_fileout = fsbridge::fopen(m_file_path, "a"); | m_fileout = fsbridge::fopen(m_file_path, "a"); | ||||
if (!m_fileout) { | if (!m_fileout) { | ||||
Show All 28 Lines | bool BCLog::Logger::StartLogging() { | ||||
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() { | ||||
LockGuard scoped_lock(m_cs); | StdLockGuard 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(); | m_print_callbacks.clear(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Lines | for (char ch_in : str) { | ||||
ret += strprintf("\\x%02x", ch); | ret += strprintf("\\x%02x", ch); | ||||
} | } | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
} // namespace BCLog | } // namespace BCLog | ||||
void BCLog::Logger::LogPrintStr(const std::string &str) { | void BCLog::Logger::LogPrintStr(const std::string &str) { | ||||
LockGuard scoped_lock(m_cs); | StdLockGuard scoped_lock(m_cs); | ||||
std::string str_prefixed = LogEscapeMessage(str); | std::string str_prefixed = LogEscapeMessage(str); | ||||
if (m_log_threadnames && m_started_new_line) { | if (m_log_threadnames && m_started_new_line) { | ||||
str_prefixed.insert(0, "[" + util::ThreadGetInternalName() + "] "); | str_prefixed.insert(0, "[" + util::ThreadGetInternalName() + "] "); | ||||
} | } | ||||
str_prefixed = LogTimestampStr(str_prefixed); | str_prefixed = LogTimestampStr(str_prefixed); | ||||
▲ Show 20 Lines • Show All 122 Lines • Show Last 20 Lines |