22#include <source_location>
24#include <unordered_map>
28#include <boost/test/unit_test.hpp>
43 std::vector<std::string> lines;
45 for (std::string line; std::getline(
ifs, line);) {
46 lines.push_back(std::move(line));
92 LogInfo(
"Sentinel log to reopen log file");
125 std::vector<Case>
cases = {
134 std::vector<std::string> expected;
152 std::vector<std::string> expected = {
155 "[warning] foo9: bar9",
156 "[error] foo10: bar10",
174 std::vector<std::string> expected;
176 LogDebug(category,
"foo: %s\n",
"bar");
201 LogDebug(
BCLog::NET,
"debug_%s. This log level is the same as the global one but lower than the category-specific one, which takes precedence.", 6);
203 std::vector<std::string> expected = {
220 const char*
argv_test[] = {
"bitcoind",
"-loglevel=debug"};
234 const char*
argv_test[] = {
"bitcoind",
"-loglevel=net:trace"};
253 const char*
argv_test[] = {
"bitcoind",
"-loglevel=debug",
"-loglevel=net:trace",
"-loglevel=http:info"};
376 case Location::INFO_1:
379 case Location::INFO_2:
382 case Location::DEBUG_LOG:
385 case Location::INFO_NOLIMIT:
398 std::source_location
source = std::source_location::current())
404 std::ofstream
ofs(
LogInstance().m_file_path.std_path(), std::ios::out | std::ios::trunc);
409 if (status == Status::STILL_SUPPRESSED) {
414 if (status == Status::NEWLY_SUPPRESSED) {
460 for (Location
location : {Location::DEBUG_LOG, Location::INFO_NOLIMIT}) {
461 for (
int i = 0; i <
num_lines + 2; ++i) {
#define Assert(val)
Identity function.
@ ALLOW_ANY
disable validation
bool ParseParameters(int argc, const char *const argv[], std::string &error)
void AddArg(const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat)
Add argument.
static std::shared_ptr< LogRateLimiter > Create(SchedulerFunction &&scheduler_func, uint64_t max_bytes, std::chrono::seconds reset_window)
Status
Suppression status of a source log location.
bool m_log_sourcelocations
void SetCategoryLogLevel(const std::unordered_map< LogFlags, Level > &levels) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
void SetLogLevel(Level level)
void SetRateLimiting(std::shared_ptr< LogRateLimiter > limiter) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
void EnableCategory(LogFlags flag)
std::atomic< bool > m_reopen_file
std::unordered_map< LogFlags, Level > CategoryLevels() const EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
void LogPrintStr(std::string_view str, SourceLocation &&source_loc, BCLog::LogFlags category, BCLog::Level level, bool should_ratelimit) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Send a string to the log output.
std::string LogCategoriesString() const
Returns a string with the log categories in alphabetical order.
void DisableCategory(LogFlags flag)
RAII-style object that outputs timing information to logs.
Simple class for background tasks that should be run periodically or once "after a while".
void MockForward(std::chrono::seconds delta_seconds) EXCLUSIVE_LOCKS_REQUIRED(!newTaskMutex)
Mock the scheduler to fast forward in time.
void serviceQueue() EXCLUSIVE_LOCKS_REQUIRED(!newTaskMutex)
Services the queue 'forever'.
void scheduleEvery(Function f, std::chrono::milliseconds delta) EXCLUSIVE_LOCKS_REQUIRED(!newTaskMutex)
Repeat f until the scheduler is stopped.
std::thread m_service_thread
void stop() EXCLUSIVE_LOCKS_REQUIRED(!newTaskMutex)
Tell any threads running serviceQueue to stop as soon as the current task is done.
void scheduleFromNow(Function f, std::chrono::milliseconds delta) EXCLUSIVE_LOCKS_REQUIRED(!newTaskMutex)
Call f once after the delta has passed.
Like std::source_location, but allowing to override the function name.
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
Common init functions shared by bitcoin-node, bitcoin-wallet, etc.
#define LogPrintLevel_(category, level, should_ratelimit,...)
#define LogTrace(category,...)
#define LogDebug(category,...)
bool GetLogCategory(BCLog::LogFlags &flag, std::string_view str)
Return true if str parses as a log category and set the flag.
BCLog::Logger & LogInstance()
static std::vector< std::string > ReadDebugLogLines()
BOOST_FIXTURE_TEST_CASE(logging_LogPrintStr, LogSetup)
BOOST_AUTO_TEST_CASE(logging_timer)
static void ResetLogger()
constexpr uint64_t RATELIMIT_MAX_BYTES
constexpr auto DEFAULT_LOG_LEVEL
util::Result< void > SetLoggingLevel(const ArgsManager &args)
std::vector< std::string > SplitString(std::string_view str, char sep)
std::string TrimString(std::string_view str, std::string_view pattern=" \f\n\r\t\v")
std::string RemovePrefix(std::string_view str, std::string_view prefix)
auto Join(const C &container, const S &separator, UnaryOp unary_op)
Join all container items.
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
Keeps track of an individual source location and how many available bytes are left for logging from i...
uint64_t m_available_bytes
Remaining bytes.
bool Consume(uint64_t bytes)
Updates internal accounting and returns true if enough available_bytes were remaining.
uint64_t m_dropped_bytes
Number of bytes that were consumed but didn't fit in the available bytes.
ArgsManager m_args
Test-specific arguments and settings.
std::unordered_map< BCLog::LogFlags, BCLog::Level > prev_category_levels
BCLog::Level prev_log_level
bool prev_log_threadnames
bool prev_log_sourcelocations
BCLog::CategoryMask prev_category_mask
std::shared_ptr< BCLog::LogRateLimiter > GetLimiter(size_t max_bytes, std::chrono::seconds window)
void MockForwardAndSync(std::chrono::seconds duration)
BOOST_CHECK_EQUAL_COLLECTIONS(R1L.begin(), R1L.end(), R1Array, R1Array+uint256::size())
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.