Bitcoin Core 30.99.0
P2P Digital Currency
logging.h
Go to the documentation of this file.
1// Copyright (c) 2009-2010 Satoshi Nakamoto
2// Copyright (c) 2009-present The Bitcoin Core developers
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#ifndef BITCOIN_LOGGING_H
7#define BITCOIN_LOGGING_H
8
9#include <crypto/siphash.h>
10#include <threadsafety.h>
11#include <tinyformat.h>
12#include <util/fs.h>
13#include <util/string.h>
14#include <util/time.h>
15
16#include <atomic>
17#include <cstdint>
18#include <cstring>
19#include <functional>
20#include <list>
21#include <memory>
22#include <mutex>
23#include <source_location>
24#include <string>
25#include <unordered_map>
26#include <unordered_set>
27#include <vector>
28
29static const bool DEFAULT_LOGTIMEMICROS = false;
30static const bool DEFAULT_LOGIPS = false;
31static const bool DEFAULT_LOGTIMESTAMPS = true;
32static const bool DEFAULT_LOGTHREADNAMES = false;
33static const bool DEFAULT_LOGSOURCELOCATIONS = false;
34static constexpr bool DEFAULT_LOGLEVELALWAYS = false;
35extern const char * const DEFAULT_DEBUGLOGFILE;
36
37extern bool fLogIPs;
38
40 bool operator()(const std::source_location& lhs, const std::source_location& rhs) const noexcept
41 {
42 return lhs.line() == rhs.line() && std::string_view(lhs.file_name()) == std::string_view(rhs.file_name());
43 }
44};
45
47 size_t operator()(const std::source_location& s) const noexcept
48 {
49 // Use CSipHasher(0, 0) as a simple way to get uniform distribution.
50 return size_t(CSipHasher(0, 0)
51 .Write(s.line())
52 .Write(MakeUCharSpan(std::string_view{s.file_name()}))
53 .Finalize());
54 }
55};
56
58 std::string category;
59 bool active;
60};
61
62namespace BCLog {
63 using CategoryMask = uint64_t;
66 NET = (CategoryMask{1} << 0),
67 TOR = (CategoryMask{1} << 1),
68 MEMPOOL = (CategoryMask{1} << 2),
69 HTTP = (CategoryMask{1} << 3),
70 BENCH = (CategoryMask{1} << 4),
71 ZMQ = (CategoryMask{1} << 5),
73 RPC = (CategoryMask{1} << 7),
75 ADDRMAN = (CategoryMask{1} << 9),
77 REINDEX = (CategoryMask{1} << 11),
79 RAND = (CategoryMask{1} << 13),
80 PRUNE = (CategoryMask{1} << 14),
81 PROXY = (CategoryMask{1} << 15),
83 LIBEVENT = (CategoryMask{1} << 17),
84 COINDB = (CategoryMask{1} << 18),
85 QT = (CategoryMask{1} << 19),
86 LEVELDB = (CategoryMask{1} << 20),
88 I2P = (CategoryMask{1} << 22),
89 IPC = (CategoryMask{1} << 23),
90#ifdef DEBUG_LOCKCONTENTION
91 LOCK = (CategoryMask{1} << 24),
92#endif
95 SCAN = (CategoryMask{1} << 27),
97 KERNEL = (CategoryMask{1} << 29),
99 };
100 enum class Level {
101 Trace = 0, // High-volume or detailed logging for development/debugging
102 Debug, // Reasonably noisy logging, but still usable in production
103 Info, // Default
104 Warning,
105 Error,
106 };
108 constexpr size_t DEFAULT_MAX_LOG_BUFFER{1'000'000}; // buffer up to 1MB of log data prior to StartLogging
109 constexpr uint64_t RATELIMIT_MAX_BYTES{1024 * 1024}; // maximum number of bytes per source location that can be logged within the RATELIMIT_WINDOW
110 constexpr auto RATELIMIT_WINDOW{1h}; // time window after which log ratelimit stats are reset
111 constexpr bool DEFAULT_LOGRATELIMIT{true};
112
115 {
116 public:
118 struct Stats {
122 uint64_t m_dropped_bytes{0};
123
124 Stats(uint64_t max_bytes) : m_available_bytes{max_bytes} {}
126 bool Consume(uint64_t bytes);
127 };
128
129 private:
131
133 std::unordered_map<std::source_location, Stats, SourceLocationHasher, SourceLocationEqual> m_source_locations GUARDED_BY(m_mutex);
135 std::atomic<bool> m_suppression_active{false};
136 LogRateLimiter(uint64_t max_bytes, std::chrono::seconds reset_window);
137
138 public:
139 using SchedulerFunction = std::function<void(std::function<void()>, std::chrono::milliseconds)>;
148 static std::shared_ptr<LogRateLimiter> Create(
149 SchedulerFunction&& scheduler_func,
150 uint64_t max_bytes,
151 std::chrono::seconds reset_window);
153 const uint64_t m_max_bytes;
155 const std::chrono::seconds m_reset_window;
157 enum class Status {
158 UNSUPPRESSED, // string fits within the limit
159 NEWLY_SUPPRESSED, // suppression has started since this string
160 STILL_SUPPRESSED, // suppression is still ongoing
161 };
164 [[nodiscard]] Status Consume(
165 const std::source_location& source_loc,
166 const std::string& str) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
171 };
172
173 class Logger
174 {
175 public:
176 struct BufferedLog {
177 SystemClock::time_point now;
178 std::chrono::seconds mocktime;
179 std::string str, threadname;
180 std::source_location source_loc;
183 };
184
185 private:
186 mutable StdMutex m_cs; // Can not use Mutex from sync.h because in debug mode it would cause a deadlock when a potential deadlock was detected
187
188 FILE* m_fileout GUARDED_BY(m_cs) = nullptr;
189 std::list<BufferedLog> m_msgs_before_open GUARDED_BY(m_cs);
190 bool m_buffering GUARDED_BY(m_cs) = true;
191 size_t m_max_buffer_memusage GUARDED_BY(m_cs){DEFAULT_MAX_LOG_BUFFER};
192 size_t m_cur_buffer_memusage GUARDED_BY(m_cs){0};
193 size_t m_buffer_lines_discarded GUARDED_BY(m_cs){0};
194
196 std::shared_ptr<LogRateLimiter> m_limiter GUARDED_BY(m_cs);
197
199 std::unordered_map<LogFlags, Level> m_category_log_levels GUARDED_BY(m_cs);
200
203 std::atomic<Level> m_log_level{DEFAULT_LOG_LEVEL};
204
206 std::atomic<CategoryMask> m_categories{BCLog::NONE};
207
208 void FormatLogStrInPlace(std::string& str, LogFlags category, Level level, const std::source_location& source_loc, std::string_view threadname, SystemClock::time_point now, std::chrono::seconds mocktime) const;
209
210 std::string LogTimestampStr(SystemClock::time_point now, std::chrono::seconds mocktime) const;
211
213 std::list<std::function<void(const std::string&)>> m_print_callbacks GUARDED_BY(m_cs) {};
214
216 void LogPrintStr_(std::string_view str, std::source_location&& source_loc, BCLog::LogFlags category, BCLog::Level level, bool should_ratelimit)
218
219 std::string GetLogPrefix(LogFlags category, Level level) const;
220
221 public:
222 bool m_print_to_console = false;
223 bool m_print_to_file = false;
224
230
231 fs::path m_file_path;
232 std::atomic<bool> m_reopen_file{false};
233
235 void LogPrintStr(std::string_view str, std::source_location&& source_loc, BCLog::LogFlags category, BCLog::Level level, bool should_ratelimit)
237
240 {
241 StdLockGuard scoped_lock(m_cs);
242 return m_buffering || m_print_to_console || m_print_to_file || !m_print_callbacks.empty();
243 }
244
246 std::list<std::function<void(const std::string&)>>::iterator PushBackCallback(std::function<void(const std::string&)> fun) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
247 {
248 StdLockGuard scoped_lock(m_cs);
249 m_print_callbacks.push_back(std::move(fun));
250 return --m_print_callbacks.end();
251 }
252
254 void DeleteCallback(std::list<std::function<void(const std::string&)>>::iterator it) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
255 {
256 StdLockGuard scoped_lock(m_cs);
257 m_print_callbacks.erase(it);
258 }
259
261 {
262 StdLockGuard scoped_lock(m_cs);
263 return m_print_callbacks.size();
264 }
265
270
272 {
273 StdLockGuard scoped_lock(m_cs);
274 m_limiter = std::move(limiter);
275 }
276
284
285 void ShrinkDebugFile();
286
288 {
289 StdLockGuard scoped_lock(m_cs);
290 return m_category_log_levels;
291 }
292 void SetCategoryLogLevel(const std::unordered_map<LogFlags, Level>& levels) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
293 {
294 StdLockGuard scoped_lock(m_cs);
295 m_category_log_levels = levels;
296 }
297 void AddCategoryLogLevel(LogFlags category, Level level)
298 {
299 StdLockGuard scoped_lock(m_cs);
300 m_category_log_levels[category] = level;
301 }
302 bool SetCategoryLogLevel(std::string_view category_str, std::string_view level_str) EXCLUSIVE_LOCKS_REQUIRED(!m_cs);
303
304 Level LogLevel() const { return m_log_level.load(); }
305 void SetLogLevel(Level level) { m_log_level = level; }
306 bool SetLogLevel(std::string_view level);
307
308 CategoryMask GetCategoryMask() const { return m_categories.load(); }
309
310 void EnableCategory(LogFlags flag);
311 bool EnableCategory(std::string_view str);
312 void DisableCategory(LogFlags flag);
313 bool DisableCategory(std::string_view str);
314
315 bool WillLogCategory(LogFlags category) const;
317
319 std::vector<LogCategory> LogCategoriesList() const;
321 std::string LogCategoriesString() const
322 {
323 return util::Join(LogCategoriesList(), ", ", [&](const LogCategory& i) { return i.category; });
324 };
325
327 std::string LogLevelsString() const;
328
330 static std::string LogLevelToStr(BCLog::Level level);
331
332 bool DefaultShrinkDebugFile() const;
333 };
334
335} // namespace BCLog
336
338
340static inline bool LogAcceptCategory(BCLog::LogFlags category, BCLog::Level level)
341{
342 return LogInstance().WillLogCategoryLevel(category, level);
343}
344
346bool GetLogCategory(BCLog::LogFlags& flag, std::string_view str);
347
348template <typename... Args>
349inline void LogPrintFormatInternal(std::source_location&& source_loc, BCLog::LogFlags flag, BCLog::Level level, bool should_ratelimit, util::ConstevalFormatString<sizeof...(Args)> fmt, const Args&... args)
350{
351 if (LogInstance().Enabled()) {
352 std::string log_msg;
353 try {
354 log_msg = tfm::format(fmt, args...);
355 } catch (tinyformat::format_error& fmterr) {
356 log_msg = "Error \"" + std::string{fmterr.what()} + "\" while formatting log message: " + fmt.fmt;
357 }
358 LogInstance().LogPrintStr(log_msg, std::move(source_loc), flag, level, should_ratelimit);
359 }
360}
361
362#define LogPrintLevel_(category, level, should_ratelimit, ...) LogPrintFormatInternal(std::source_location::current(), category, level, should_ratelimit, __VA_ARGS__)
363
364// Log unconditionally. Uses basic rate limiting to mitigate disk filling attacks.
365// Be conservative when using functions that unconditionally log to debug.log!
366// It should not be the case that an inbound peer can fill up a user's storage
367// with debug.log entries.
368#define LogInfo(...) LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Info, /*should_ratelimit=*/true, __VA_ARGS__)
369#define LogWarning(...) LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Warning, /*should_ratelimit=*/true, __VA_ARGS__)
370#define LogError(...) LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Error, /*should_ratelimit=*/true, __VA_ARGS__)
371
372// Deprecated unconditional logging.
373#define LogPrintf(...) LogInfo(__VA_ARGS__)
374
375// Use a macro instead of a function for conditional logging to prevent
376// evaluating arguments when logging for the category is not enabled.
377
378// Log by prefixing the output with the passed category name and severity level. This can either
379// log conditionally if the category is allowed or unconditionally if level >= BCLog::Level::Info
380// is passed. If this function logs unconditionally, logging to disk is rate-limited. This is
381// important so that callers don't need to worry about accidentally introducing a disk-fill
382// vulnerability if level >= Info is used. Additionally, users specifying -debug are assumed to be
383// developers or power users who are aware that -debug may cause excessive disk usage due to logging.
384#define LogPrintLevel(category, level, ...) \
385 do { \
386 if (LogAcceptCategory((category), (level))) { \
387 bool rate_limit{level >= BCLog::Level::Info}; \
388 LogPrintLevel_(category, level, rate_limit, __VA_ARGS__); \
389 } \
390 } while (0)
391
392// Log conditionally, prefixing the output with the passed category name.
393#define LogDebug(category, ...) LogPrintLevel(category, BCLog::Level::Debug, __VA_ARGS__)
394#define LogTrace(category, ...) LogPrintLevel(category, BCLog::Level::Trace, __VA_ARGS__)
395
396#endif // BITCOIN_LOGGING_H
ArgsManager & args
Definition: bitcoind.cpp:277
Fixed window rate limiter for logging.
Definition: logging.h:115
std::unordered_map< std::source_location, Stats, SourceLocationHasher, SourceLocationEqual > m_source_locations GUARDED_BY(m_mutex)
Stats for each source location that has attempted to log something.
static std::shared_ptr< LogRateLimiter > Create(SchedulerFunction &&scheduler_func, uint64_t max_bytes, std::chrono::seconds reset_window)
Definition: logging.cpp:378
std::function< void(std::function< void()>, std::chrono::milliseconds)> SchedulerFunction
Definition: logging.h:139
const uint64_t m_max_bytes
Maximum number of bytes logged per location per window.
Definition: logging.h:153
LogRateLimiter(uint64_t max_bytes, std::chrono::seconds reset_window)
Definition: logging.cpp:375
Status Consume(const std::source_location &source_loc, const std::string &str) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Consumes source_loc's available bytes corresponding to the size of the (formatted) str and returns it...
Definition: logging.cpp:390
bool SuppressionsActive() const
Returns true if any log locations are currently being suppressed.
Definition: logging.h:170
const std::chrono::seconds m_reset_window
Interval after which the window is reset.
Definition: logging.h:155
Status
Suppression status of a source log location.
Definition: logging.h:157
void Reset() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Resets all usage to zero. Called periodically by the scheduler.
Definition: logging.cpp:554
std::atomic< bool > m_suppression_active
Whether any log locations are suppressed. Cached view on m_source_locations for performance reasons.
Definition: logging.h:135
static std::string LogLevelToStr(BCLog::Level level)
Returns the string representation of a log level.
Definition: logging.cpp:233
bool m_always_print_category_level
Definition: logging.h:229
size_t m_buffer_lines_discarded GUARDED_BY(m_cs)
Definition: logging.h:193
FILE *m_fileout GUARDED_BY(m_cs)
bool m_buffering GUARDED_BY(m_cs)
Buffer messages before logging can be started.
bool WillLogCategory(LogFlags category) const
Definition: logging.cpp:149
void LogPrintStr(std::string_view str, std::source_location &&source_loc, BCLog::LogFlags category, BCLog::Level level, bool should_ratelimit) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Send a string to the log output.
Definition: logging.cpp:423
std::list< BufferedLog > m_msgs_before_open GUARDED_BY(m_cs)
std::atomic< CategoryMask > m_categories
Log categories bitfield.
Definition: logging.h:206
std::string LogTimestampStr(SystemClock::time_point now, std::chrono::seconds mocktime) const
Definition: logging.cpp:299
size_t m_cur_buffer_memusage GUARDED_BY(m_cs)
Definition: logging.h:192
bool DefaultShrinkDebugFile() const
Definition: logging.cpp:167
std::unordered_map< LogFlags, Level > m_category_log_levels GUARDED_BY(m_cs)
Category-specific log level. Overrides m_log_level.
bool m_log_sourcelocations
Definition: logging.h:228
void SetCategoryLogLevel(const std::unordered_map< LogFlags, Level > &levels) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Definition: logging.h:292
void SetLogLevel(Level level)
Definition: logging.h:305
std::atomic< Level > m_log_level
If there is no category-specific log level, all logs with a severity level lower than m_log_level wil...
Definition: logging.h:203
Level LogLevel() const
Definition: logging.h:304
CategoryMask GetCategoryMask() const
Definition: logging.h:308
bool WillLogCategoryLevel(LogFlags category, Level level) const EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Definition: logging.cpp:154
fs::path m_file_path
Definition: logging.h:231
bool m_log_time_micros
Definition: logging.h:226
bool m_log_threadnames
Definition: logging.h:227
std::list< std::function< void(conststd::string &)> >::iterator PushBackCallback(std::function< void(const std::string &)> fun) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Connect a slot to the print signal and return the connection.
Definition: logging.h:246
void SetRateLimiting(std::shared_ptr< LogRateLimiter > limiter) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Definition: logging.h:271
void DisableLogging() EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Disable logging This offers a slight speedup and slightly smaller memory usage compared to leaving th...
Definition: logging.cpp:111
std::vector< LogCategory > LogCategoriesList() const
Returns a vector of the log categories in alphabetical order.
Definition: logging.cpp:277
bool StartLogging() EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Start logging (and flush all buffered messages)
Definition: logging.cpp:54
void EnableCategory(LogFlags flag)
Definition: logging.cpp:123
size_t m_max_buffer_memusage GUARDED_BY(m_cs)
Definition: logging.h:191
bool m_log_timestamps
Definition: logging.h:225
void DeleteCallback(std::list< std::function< void(const std::string &)> >::iterator it) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Delete a connection.
Definition: logging.h:254
std::string GetLogPrefix(LogFlags category, Level level) const
Definition: logging.cpp:342
void LogPrintStr_(std::string_view str, std::source_location &&source_loc, BCLog::LogFlags category, BCLog::Level level, bool should_ratelimit) EXCLUSIVE_LOCKS_REQUIRED(m_cs)
Send a string to the log output (internal)
Definition: logging.cpp:430
void DisconnectTestLogger() EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Only for testing.
Definition: logging.cpp:98
void AddCategoryLogLevel(LogFlags category, Level level)
Definition: logging.h:297
std::string LogLevelsString() const
Returns a string with all user-selectable log levels.
Definition: logging.cpp:293
size_t NumConnections()
Definition: logging.h:260
std::atomic< bool > m_reopen_file
Definition: logging.h:232
void ShrinkDebugFile()
Definition: logging.cpp:513
bool m_print_to_file
Definition: logging.h:223
void FormatLogStrInPlace(std::string &str, LogFlags category, Level level, const std::source_location &source_loc, std::string_view threadname, SystemClock::time_point now, std::chrono::seconds mocktime) const
Definition: logging.cpp:406
std::unordered_map< LogFlags, Level > CategoryLevels() const EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Definition: logging.h:287
bool m_print_to_console
Definition: logging.h:222
std::shared_ptr< LogRateLimiter > m_limiter GUARDED_BY(m_cs)
Manages the rate limiting of each log location.
std::list< std::function< void(const std::string &)> > m_print_callbacks GUARDED_BY(m_cs)
Slots that connect to the print signal.
Definition: logging.h:213
StdMutex m_cs
Definition: logging.h:186
bool Enabled() const EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Returns whether logs will be written to any output.
Definition: logging.h:239
std::string LogCategoriesString() const
Returns a string with the log categories in alphabetical order.
Definition: logging.h:321
void DisableCategory(LogFlags flag)
Definition: logging.cpp:136
SipHash-2-4.
Definition: siphash.h:15
CSipHasher & Write(uint64_t data)
Hash a 64-bit integer worth of data It is treated as if this was the little-endian interpretation of ...
Definition: siphash.cpp:32
static const bool DEFAULT_LOGTIMESTAMPS
Definition: logging.h:31
bool GetLogCategory(BCLog::LogFlags &flag, std::string_view str)
Return true if str parses as a log category and set the flag.
Definition: logging.cpp:219
static const bool DEFAULT_LOGIPS
Definition: logging.h:30
static const bool DEFAULT_LOGTHREADNAMES
Definition: logging.h:32
static bool LogAcceptCategory(BCLog::LogFlags category, BCLog::Level level)
Return true if log accepts specified category, at the specified level.
Definition: logging.h:340
BCLog::Logger & LogInstance()
Definition: logging.cpp:26
static const bool DEFAULT_LOGSOURCELOCATIONS
Definition: logging.h:33
bool fLogIPs
Definition: logging.cpp:47
static const bool DEFAULT_LOGTIMEMICROS
Definition: logging.h:29
const char *const DEFAULT_DEBUGLOGFILE
Definition: logging.cpp:23
void LogPrintFormatInternal(std::source_location &&source_loc, BCLog::LogFlags flag, BCLog::Level level, bool should_ratelimit, util::ConstevalFormatString< sizeof...(Args)> fmt, const Args &... args)
Definition: logging.h:349
static constexpr bool DEFAULT_LOGLEVELALWAYS
Definition: logging.h:34
constexpr auto RATELIMIT_WINDOW
Definition: logging.h:110
Level
Definition: logging.h:100
constexpr bool DEFAULT_LOGRATELIMIT
Definition: logging.h:111
constexpr uint64_t RATELIMIT_MAX_BYTES
Definition: logging.h:109
constexpr size_t DEFAULT_MAX_LOG_BUFFER
Definition: logging.h:108
uint64_t CategoryMask
Definition: logging.h:63
constexpr auto DEFAULT_LOG_LEVEL
Definition: logging.h:107
LogFlags
Definition: logging.h:64
@ ESTIMATEFEE
Definition: logging.h:74
@ TXRECONCILIATION
Definition: logging.h:94
@ RAND
Definition: logging.h:79
@ BLOCKSTORAGE
Definition: logging.h:93
@ COINDB
Definition: logging.h:84
@ REINDEX
Definition: logging.h:77
@ TXPACKAGES
Definition: logging.h:96
@ WALLETDB
Definition: logging.h:72
@ SCAN
Definition: logging.h:95
@ ADDRMAN
Definition: logging.h:75
@ ALL
Definition: logging.h:98
@ RPC
Definition: logging.h:73
@ HTTP
Definition: logging.h:69
@ LEVELDB
Definition: logging.h:86
@ NONE
Definition: logging.h:65
@ VALIDATION
Definition: logging.h:87
@ MEMPOOLREJ
Definition: logging.h:82
@ PRUNE
Definition: logging.h:80
@ TOR
Definition: logging.h:67
@ LIBEVENT
Definition: logging.h:83
@ CMPCTBLOCK
Definition: logging.h:78
@ PROXY
Definition: logging.h:81
@ ZMQ
Definition: logging.h:71
@ IPC
Definition: logging.h:89
@ MEMPOOL
Definition: logging.h:68
@ SELECTCOINS
Definition: logging.h:76
@ I2P
Definition: logging.h:88
@ BENCH
Definition: logging.h:70
@ NET
Definition: logging.h:66
@ KERNEL
Definition: logging.h:97
@ QT
Definition: logging.h:85
void format(std::ostream &out, FormatStringCheck< sizeof...(Args)> fmt, const Args &... args)
Format list of arguments to the stream according to given format string.
Definition: tinyformat.h:1079
auto Join(const C &container, const S &separator, UnaryOp unary_op)
Join all container items.
Definition: string.h:204
constexpr auto MakeUCharSpan(const V &v) -> decltype(UCharSpanCast(std::span{v}))
Like the std::span constructor, but for (const) unsigned char member types only.
Definition: span.h:111
Keeps track of an individual source location and how many available bytes are left for logging from i...
Definition: logging.h:118
uint64_t m_available_bytes
Remaining bytes.
Definition: logging.h:120
Stats(uint64_t max_bytes)
Definition: logging.h:124
bool Consume(uint64_t bytes)
Updates internal accounting and returns true if enough available_bytes were remaining.
Definition: logging.cpp:572
uint64_t m_dropped_bytes
Number of bytes that were consumed but didn't fit in the available bytes.
Definition: logging.h:122
std::chrono::seconds mocktime
Definition: logging.h:178
std::string threadname
Definition: logging.h:179
std::source_location source_loc
Definition: logging.h:180
SystemClock::time_point now
Definition: logging.h:177
bool active
Definition: logging.h:59
std::string category
Definition: logging.h:58
bool operator()(const std::source_location &lhs, const std::source_location &rhs) const noexcept
Definition: logging.h:40
size_t operator()(const std::source_location &s) const noexcept
Definition: logging.h:47
A wrapper for a compile-time partially validated format string.
Definition: string.h:92
#define LOCK(cs)
Definition: sync.h:259
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:51