28 static int FileWriteStr(
const std::string &str, FILE *fp)
30 return fwrite(str.data(), 1, str.size(), fp);
70 m_categories &= ~flag;
77 DisableCategory(flag);
83 return (m_categories.load(std::memory_order_relaxed) & category) != 0;
133 if (category_desc.category == str) {
134 flag = category_desc.flag;
148 if (outcount != 0)
ret +=
", ";
149 ret += category_desc.category;
158 std::vector<CLogCategoryActive>
ret;
163 catActive.
category = category_desc.category;
164 catActive.
active = LogAcceptCategory(category_desc.flag);
173 std::string strStamped;
175 if (!m_log_timestamps)
178 if (m_started_new_line) {
181 if (m_log_time_micros) {
182 strStamped.pop_back();
183 strStamped +=
strprintf(
".%06dZ", nTimeMicros%1000000);
189 strStamped +=
' ' + str;
193 if (!str.empty() && str[str.size()-1] ==
'\n')
194 m_started_new_line =
true;
196 m_started_new_line =
false;
203 std::string strTimestamped = LogTimestampStr(str);
205 if (m_print_to_console) {
207 fwrite(strTimestamped.data(), 1, strTimestamped.size(), stdout);
210 if (m_print_to_file) {
211 std::lock_guard<std::mutex> scoped_lock(m_file_mutex);
214 if (m_fileout ==
nullptr) {
215 m_msgs_before_open.push_back(strTimestamped);
221 m_reopen_file =
false;
224 setbuf(new_fileout,
nullptr);
226 m_fileout = new_fileout;
229 FileWriteStr(strTimestamped, m_fileout);
237 constexpr
size_t RECENT_DEBUG_HISTORY_SIZE = 10 * 1000000;
239 assert(!m_file_path.empty());
247 log_size = fs::file_size(m_file_path);
248 }
catch (
const fs::filesystem_error&) {}
252 if (file && log_size > 11 * (RECENT_DEBUG_HISTORY_SIZE / 10))
255 std::vector<char> vch(RECENT_DEBUG_HISTORY_SIZE, 0);
256 if (fseek(file, -((
long)vch.size()), SEEK_END)) {
257 LogPrintf(
"Failed to shrink debug log file: fseek(...) failed\n");
261 int nBytes = fread(vch.data(), 1, vch.size(), file);
267 fwrite(vch.data(), 1, nBytes, file);
271 else if (file !=
nullptr)
void EnableCategory(LogFlags flag)
FILE * fopen(const fs::path &p, const char *mode)
std::string ListLogCategories()
Returns a string with the log categories.
UniValue ret(UniValue::VARR)
void LogPrintStr(const std::string &str)
Send a string to the log output.
bool push_back(const UniValue &val)
void DisableCategory(LogFlags flag)
bool WillLogCategory(LogFlags category) const
bool GetLogCategory(BCLog::LogFlags &flag, const std::string &str)
Return true if str parses as a log category and set the flag.
std::string FormatISO8601DateTime(int64_t nTime)
ISO 8601 formatting is preferred.
const CLogCategoryDesc LogCategories[]
std::list< std::string > m_msgs_before_open
const char *const DEFAULT_DEBUGLOGFILE
std::vector< CLogCategoryActive > ListActiveLogCategories()
Returns a vector of the active log categories.
BCLog::Logger *const g_logger
NOTE: the logger instances is leaked on exit.
std::string LogTimestampStr(const std::string &str)
bool DefaultShrinkDebugFile() const