31 static int FileWriteStr(
const std::string &str, FILE *fp)
33 return fwrite(str.data(), 1, str.size(), fp);
71 m_categories &= ~flag;
78 DisableCategory(flag);
84 return (m_categories.load(std::memory_order_relaxed) & category) != 0;
140 if (category_desc.category == str) {
141 flag = category_desc.flag;
155 if (outcount != 0) ret +=
", ";
156 ret += category_desc.category;
165 std::vector<CLogCategoryActive> ret;
170 catActive.
category = category_desc.category;
171 catActive.
active = LogAcceptCategory(category_desc.flag);
172 ret.push_back(catActive);
180 std::string strStamped;
182 if (!m_log_timestamps)
185 if (m_started_new_line) {
188 if (m_log_time_micros) {
189 strStamped.pop_back();
190 strStamped +=
strprintf(
".%06dZ", nTimeMicros % 1000000);
196 strStamped +=
' ' + str;
200 if (!str.empty() && str[str.size()-1] ==
'\n')
201 m_started_new_line =
true;
203 m_started_new_line =
false;
210 std::string strTimestamped = LogTimestampStr(str);
212 if (m_print_to_console) {
214 fwrite(strTimestamped.data(), 1, strTimestamped.size(), stdout);
218 if (m_print_to_file) {
219 std::lock_guard<std::mutex> scoped_lock(m_file_mutex);
222 if (m_fileout ==
nullptr) {
223 m_msgs_before_open.push_back(strTimestamped);
228 m_reopen_file =
false;
231 setbuf(new_fileout,
nullptr);
233 m_fileout = new_fileout;
236 FileWriteStr(strTimestamped, m_fileout);
244 constexpr
size_t RECENT_DEBUG_HISTORY_SIZE = 10 * 1000000;
246 assert(!m_file_path.empty());
250 if (file && fs::file_size(m_file_path) > RECENT_DEBUG_HISTORY_SIZE) {
252 std::vector<char> vch(200000, 0);
253 fseek(file, -((
long)vch.size()), SEEK_END);
254 int nBytes = fread(vch.data(), 1, vch.size(), file);
259 fwrite(vch.data(), 1, nBytes, file);
262 }
else if (file !=
nullptr)
270 accept(LogAcceptCategory(_category)),
bool WillLogCategory(LogFlags category) const
bool Enabled() const
Returns whether logs will be written to any output.
std::string LogTimestampStr(const std::string &str)
std::list< std::string > m_msgs_before_open
bool DefaultShrinkDebugFile() const
void LogPrintStr(const std::string &str)
Send a string to the log output.
void EnableCategory(LogFlags flag)
void DisableCategory(LogFlags flag)
virtual ~CBatchedLogger()
CBatchedLogger(BCLog::Logger *_logger, BCLog::LogFlags _category, const std::string &_header)
PIVX.
std::vector< CLogCategoryActive > ListActiveLogCategories()
Returns a vector of the active log categories.
const CLogCategoryDesc LogCategories[]
BCLog::Logger *const g_logger
NOTE: the logger instances is leaked on exit.
bool GetLogCategory(BCLog::LogFlags &flag, const std::string &str)
Return true if str parses as a log category and set the flag.
const char *const DEFAULT_DEBUGLOGFILE
std::string ListLogCategories()
Returns a string with the supported log categories.
FILE * fopen(const fs::path &p, const char *mode)
int64_t GetTimeMicros()
Returns the system time (not mockable)
int64_t GetMockTime()
For testing.
std::string FormatISO8601DateTime(int64_t nTime)
ISO 8601 formatting is preferred.