33 static int FileWriteStr(
const std::string &str, FILE *fp)
35 return fwrite(str.data(), 1, str.size(), fp);
73 m_categories &= ~flag;
80 DisableCategory(flag);
86 return (m_categories.load(std::memory_order_relaxed) & category) != 0;
141 if (category_desc.category == str) {
142 flag = category_desc.flag;
156 if (outcount != 0) ret +=
", ";
157 ret += category_desc.category;
166 std::vector<CLogCategoryActive> ret;
171 catActive.
category = category_desc.category;
172 catActive.
active = LogAcceptCategory(category_desc.flag);
173 ret.push_back(catActive);
181 std::string strStamped;
183 if (!m_log_timestamps)
186 if (m_started_new_line)
191 if (!str.empty() && str[str.size()-1] ==
'\n')
192 m_started_new_line =
true;
194 m_started_new_line =
false;
202 if (m_print_to_console) {
204 ret = fwrite(str.data(), 1, str.size(), stdout);
206 }
else if (m_print_to_file) {
207 std::lock_guard<std::mutex> scoped_lock(m_file_mutex);
209 std::string strTimestamped = LogTimestampStr(str);
212 if (m_fileout == NULL) {
213 ret = strTimestamped.length();
214 m_msgs_before_open.push_back(strTimestamped);
219 m_reopen_file =
false;
221 setbuf(m_fileout, NULL);
224 ret = FileWriteStr(strTimestamped, m_fileout);
234 constexpr
size_t RECENT_DEBUG_HISTORY_SIZE = 10 * 1000000;
236 assert(!m_file_path.empty());
240 if (file && fs::file_size(m_file_path) > RECENT_DEBUG_HISTORY_SIZE) {
242 std::vector<char> vch(200000, 0);
243 fseek(file, -((
long)vch.size()), SEEK_END);
244 int nBytes = fread(vch.data(), 1, vch.size(), file);
249 fwrite(vch.data(), 1, nBytes, file);
252 }
else if (file != NULL)