| 200 | } |
| 201 | |
| 202 | void BCLog::Logger::LogPrintStr(const std::string &str) |
| 203 | { |
| 204 | std::string strTimestamped = LogTimestampStr(str); |
| 205 | |
| 206 | if (m_print_to_console) { |
| 207 | // print to console |
| 208 | fwrite(strTimestamped.data(), 1, strTimestamped.size(), stdout); |
| 209 | fflush(stdout); |
| 210 | } |
| 211 | if (m_print_to_file) { |
| 212 | std::lock_guard<std::mutex> scoped_lock(m_file_mutex); |
| 213 | |
| 214 | // buffer if we haven't opened the log yet |
| 215 | if (m_fileout == nullptr) { |
| 216 | m_msgs_before_open.push_back(strTimestamped); |
| 217 | } |
| 218 | else |
| 219 | { |
| 220 | // reopen the log file, if requested |
| 221 | if (m_reopen_file) { |
| 222 | m_reopen_file = false; |
| 223 | m_fileout = fsbridge::freopen(m_file_path, "a", m_fileout); |
| 224 | if (!m_fileout) { |
| 225 | return; |
| 226 | } |
| 227 | setbuf(m_fileout, nullptr); // unbuffered |
| 228 | } |
| 229 | |
| 230 | FileWriteStr(strTimestamped, m_fileout); |
| 231 | } |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | void BCLog::Logger::ShrinkDebugFile() |
| 236 | { |