41 return fwrite(str.data(), 1, str.size(),
fp);
132#ifdef DEBUG_LOCKCONTENTION
133 {BCLog::LOCK,
"lock"},
162 [](
auto a,
auto b) { return a.category < b.category; });
164 std::vector<LogCategory>
ret;
187 if (!m_log_timestamps) {
191 if (m_started_new_line) {
194 if (m_log_time_micros) {
221 for (
char ch_in : str) {
223 if ((
ch >= 32 ||
ch ==
'\n') &&
ch !=
'\x7f') {
240 if (m_log_sourcelocations && m_started_new_line) {
246 if (m_log_threadnames && m_started_new_line) {
252 m_started_new_line = !str.empty() && str[str.size() - 1] ==
'\n';
260 if (m_print_to_console) {
268 if (m_print_to_file) {
273 m_reopen_file =
false;
290 assert(!m_file_path.empty());
298 log_size = fs::file_size(m_file_path);
299 }
catch (
const fs::filesystem_error &) {
308 LogPrintf(
"Failed to shrink debug log file: fseek(...) failed\n");
312 int nBytes =
fread(vch.data(), 1, vch.size(), file);
320 }
else if (file !=
nullptr) {
326 m_categories |= category;
334 EnableCategory(flag);
347 DisableCategory(flag);
355 LogPrintf(
"Error trying to log using a category mask instead of an "
356 "explicit category.\n");
360 return (m_categories.load(std::memory_order_relaxed) & category) != 0;
bool WillLogCategory(LogFlags category) const
Return true if log accepts specified category.
std::string LogTimestampStr(const std::string &str)
void DisconnectTestLogger()
Only for testing.
bool DefaultShrinkDebugFile() const
Default for whether ShrinkDebugFile should be run.
std::vector< LogCategory > LogCategoriesList() const
Returns a vector of the log categories in alphabetical order.
void DisableCategory(LogFlags category)
void EnableCategory(LogFlags category)
bool StartLogging()
Start logging (and flush all buffered messages)
void LogPrintStr(const std::string &str, const std::string &logging_function, const std::string &source_file, const int source_line)
Send a string to the log output.
const CLogCategoryDesc LogCategories[]
static int FileWriteStr(const std::string &str, FILE *fp)
BCLog::Logger & LogInstance()
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
static const bool DEFAULT_LOGIPS
std::string LogEscapeMessage(const std::string &str)
Belts and suspenders: make sure outgoing log messages don't contain potentially suspicious characters...
FILE * fopen(const fs::path &p, const char *mode)
const std::string & ThreadGetInternalName()
Get the thread's internal (in-memory) name; used e.g.
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
static std::string ToString(const CService &ip)
std::string RemovePrefix(std::string_view str, std::string_view prefix)
int64_t GetTimeMicros()
Returns the system time (not mockable)
std::chrono::seconds GetMockTime()
For testing.
std::string FormatISO8601DateTime(int64_t nTime)
ISO 8601 formatting is preferred.
constexpr int64_t count_seconds(std::chrono::seconds t)