14 #include <unordered_map> 18 #include <boost/test/unit_test.hpp> 65 LogPrintf(
"Sentinel log to reopen log file\n");
81 BOOST_CHECK_EQUAL(micro_timer.LogMsg(
"test micros"),
"tests: test micros (1000000μs)");
101 std::ifstream file{tmp_log_path};
102 std::vector<std::string> log_lines;
103 for (std::string log; std::getline(file, log);) {
104 log_lines.push_back(log);
106 std::vector<std::string> expected = {
107 "[src1:1] [fn1] [net:debug] foo1: bar1",
108 "[src2:2] [fn2] [net] foo2: bar2",
109 "[src3:3] [fn3] [debug] foo3: bar3",
110 "[src4:4] [fn4] foo4: bar4",
112 BOOST_CHECK_EQUAL_COLLECTIONS(log_lines.begin(), log_lines.end(), expected.begin(), expected.end());
124 std::ifstream file{tmp_log_path};
125 std::vector<std::string> log_lines;
126 for (std::string log; std::getline(file, log);) {
127 log_lines.push_back(log);
129 std::vector<std::string> expected = {
132 "[net:debug] foo7: bar7",
133 "[net:info] foo8: bar8",
134 "[net:warning] foo9: bar9",
135 "[net:error] foo10: bar10",
136 "[validation] foo11: bar11",
138 BOOST_CHECK_EQUAL_COLLECTIONS(log_lines.begin(), log_lines.end(), expected.begin(), expected.end());
145 std::vector<std::pair<BCLog::LogFlags, std::string>> expected_category_names;
146 const auto category_names =
SplitString(concatenated_category_names,
',');
147 for (
const auto& category_name : category_names) {
149 const auto trimmed_category_name =
TrimString(category_name);
151 expected_category_names.emplace_back(category, trimmed_category_name);
154 std::vector<std::string> expected;
155 for (
const auto& [category,
name] : expected_category_names) {
156 LogPrint(category,
"foo: %s\n",
"bar");
157 std::string expected_log =
"[";
158 expected_log +=
name;
159 expected_log +=
"] foo: bar";
160 expected.push_back(expected_log);
163 std::ifstream file{tmp_log_path};
164 std::vector<std::string> log_lines;
165 for (std::string log; std::getline(file, log);) {
166 log_lines.push_back(log);
168 BOOST_CHECK_EQUAL_COLLECTIONS(log_lines.begin(), log_lines.end(), expected.begin(), expected.end());
189 std::vector<std::string> expected = {
190 "[http:info] foo1: bar1",
191 "[validation:warning] foo3: bar3",
192 "[rpc:error] foo4: bar4",
193 "[net:warning] foo5: bar5",
194 "[net:error] foo7: bar7",
196 std::ifstream file{tmp_log_path};
197 std::vector<std::string> log_lines;
198 for (std::string log; std::getline(file, log);) {
199 log_lines.push_back(log);
201 BOOST_CHECK_EQUAL_COLLECTIONS(log_lines.begin(), log_lines.end(), expected.begin(), expected.end());
211 const char* argv_test[] = {
"bitcoind",
"-loglevel=debug"};
223 const char* argv_test[] = {
"bitcoind",
"-loglevel=net:trace"};
230 const auto net_it{category_levels.find(BCLog::LogFlags::NET)};
231 BOOST_REQUIRE(net_it != category_levels.end());
240 const char* argv_test[] = {
"bitcoind",
"-loglevel=debug",
"-loglevel=net:trace",
"-loglevel=http:info"};
249 const auto net_it{category_levels.find(BCLog::LogFlags::NET)};
void EnableCategory(LogFlags flag)
std::unordered_map< BCLog::LogFlags, BCLog::Level > prev_category_levels
BCLog::Logger & LogInstance()
#define LogPrint(category,...)
void SetCategoryLogLevel(const std::unordered_map< LogFlags, Level > &levels)
RAII-style object that outputs timing information to logs.
BCLog::Level prev_log_level
std::atomic< bool > m_reopen_file
static void LogPrintf_(const std::string &logging_function, const std::string &source_file, const int source_line, const BCLog::LogFlags flag, const BCLog::Level level, const char *fmt, const Args &... args)
bool ParseParameters(int argc, const char *const argv[], std::string &error)
std::vector< std::string > SplitString(std::string_view str, char sep)
bool m_log_sourcelocations
const fs::path & GetDataDirBase() const
Get data directory path.
constexpr auto DEFAULT_LOG_LEVEL
Common init functions shared by bitcoin-node, bitcoin-wallet, etc.
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
void SetLoggingLevel(const ArgsManager &args)
BOOST_AUTO_TEST_CASE(logging_timer)
BOOST_AUTO_TEST_SUITE_END()
void AddArg(const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat)
Add argument.
std::unordered_map< LogFlags, Level > CategoryLevels() const
#define LogPrintLevel(category, level,...)
#define LogPrintfCategory(category,...)
void SetLogLevel(Level level)
bool GetLogCategory(BCLog::LogFlags &flag, const std::string &str)
Return true if str parses as a log category and set the flag.
#define BOOST_CHECK_EQUAL(v1, v2)
bool prev_log_threadnames
static void ResetLogger()
bool prev_log_sourcelocations
BOOST_FIXTURE_TEST_CASE(logging_LogPrintf_, LogSetup)
std::string TrimString(std::string_view str, std::string_view pattern=" \\\)
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
std::string LogCategoriesString() const
Returns a string with the log categories in alphabetical order.
#define BOOST_CHECK(expr)