14#include <unordered_map>
18#include <boost/test/unit_test.hpp>
68 LogPrintf(
"Sentinel log to reopen log file\n");
82 const std::string_view result_prefix{
"tests: msg ("};
83 BOOST_CHECK_EQUAL(micro_timer.LogMsg(
"msg").substr(0, result_prefix.size()), result_prefix);
95 std::ifstream file{tmp_log_path};
96 std::vector<std::string> log_lines;
97 for (std::string log; std::getline(file, log);) {
98 log_lines.push_back(log);
100 std::vector<std::string> expected = {
101 "[src1:1] [fn1] [net] foo1: bar1",
102 "[src2:2] [fn2] [net:info] foo2: bar2",
103 "[src3:3] [fn3] [debug] foo3: bar3",
104 "[src4:4] [fn4] foo4: bar4",
105 "[src5:5] [fn5] [debug] foo5: bar5",
106 "[src6:6] [fn6] foo6: bar6",
108 BOOST_CHECK_EQUAL_COLLECTIONS(log_lines.begin(), log_lines.end(), expected.begin(), expected.end());
119 std::ifstream file{tmp_log_path};
120 std::vector<std::string> log_lines;
121 for (std::string log; std::getline(file, log);) {
122 log_lines.push_back(log);
124 std::vector<std::string> expected = {
127 "[net:info] foo8: bar8",
128 "[net:warning] foo9: bar9",
129 "[net:error] foo10: bar10",
131 BOOST_CHECK_EQUAL_COLLECTIONS(log_lines.begin(), log_lines.end(), expected.begin(), expected.end());
141 std::ifstream file{tmp_log_path};
142 std::vector<std::string> log_lines;
143 for (std::string log; std::getline(file, log);) {
144 log_lines.push_back(log);
146 std::vector<std::string> expected = {
149 "[warning] foo9: bar9",
150 "[error] foo10: bar10",
152 BOOST_CHECK_EQUAL_COLLECTIONS(log_lines.begin(), log_lines.end(), expected.begin(), expected.end());
159 std::vector<std::pair<BCLog::LogFlags, std::string>> expected_category_names;
160 const auto category_names =
SplitString(concatenated_category_names,
',');
161 for (
const auto& category_name : category_names) {
163 const auto trimmed_category_name =
TrimString(category_name);
165 expected_category_names.emplace_back(category, trimmed_category_name);
168 std::vector<std::string> expected;
169 for (
const auto& [category,
name] : expected_category_names) {
170 LogDebug(category,
"foo: %s\n",
"bar");
171 std::string expected_log =
"[";
172 expected_log +=
name;
173 expected_log +=
"] foo: bar";
174 expected.push_back(expected_log);
177 std::ifstream file{tmp_log_path};
178 std::vector<std::string> log_lines;
179 for (std::string log; std::getline(file, log);) {
180 log_lines.push_back(log);
182 BOOST_CHECK_EQUAL_COLLECTIONS(log_lines.begin(), log_lines.end(), expected.begin(), expected.end());
203 std::vector<std::string> expected = {
204 "[http:info] foo1: bar1",
205 "[validation:warning] foo3: bar3",
206 "[rpc:error] foo4: bar4",
207 "[net:warning] foo5: bar5",
208 "[net:error] foo7: bar7",
210 std::ifstream file{tmp_log_path};
211 std::vector<std::string> log_lines;
212 for (std::string log; std::getline(file, log);) {
213 log_lines.push_back(log);
215 BOOST_CHECK_EQUAL_COLLECTIONS(log_lines.begin(), log_lines.end(), expected.begin(), expected.end());
225 const char* argv_test[] = {
"bitcoind",
"-loglevel=debug"};
230 BOOST_REQUIRE(result);
239 const char* argv_test[] = {
"bitcoind",
"-loglevel=net:trace"};
244 BOOST_REQUIRE(result);
249 BOOST_REQUIRE(net_it != category_levels.end());
258 const char* argv_test[] = {
"bitcoind",
"-loglevel=debug",
"-loglevel=net:trace",
"-loglevel=http:info"};
263 BOOST_REQUIRE(result);
@ 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.
bool m_log_sourcelocations
void SetCategoryLogLevel(const std::unordered_map< LogFlags, Level > &levels) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
void SetLogLevel(Level level)
void EnableCategory(LogFlags flag)
void LogPrintStr(std::string_view str, std::string_view logging_function, std::string_view source_file, int source_line, BCLog::LogFlags category, BCLog::Level level) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Send a string to the log output.
std::atomic< bool > m_reopen_file
std::unordered_map< LogFlags, Level > CategoryLevels() const EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
std::string LogCategoriesString() const
Returns a string with the log categories in alphabetical order.
RAII-style object that outputs timing information to logs.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
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.
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()
#define LogPrintLevel(category, level,...)
#define LogTrace(category,...)
#define LogDebug(category,...)
BOOST_FIXTURE_TEST_CASE(logging_LogPrintStr, LogSetup)
BOOST_AUTO_TEST_CASE(logging_timer)
static void ResetLogger()
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")
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
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