Skip to content

Commit 667ce3e

Browse files
committed
logging: Drop BCLog::Level::None
Now that Info-level logging is always logged, there is no further need for the "None" level, so remove it.
1 parent ab34dc6 commit 667ce3e

File tree

3 files changed

+12
-27
lines changed

3 files changed

+12
-27
lines changed

src/logging.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,6 @@ std::string BCLog::Logger::LogLevelToStr(BCLog::Level level)
215215
return "warning";
216216
case BCLog::Level::Error:
217217
return "error";
218-
case BCLog::Level::None:
219-
return "";
220218
}
221219
assert(false);
222220
}
@@ -307,8 +305,6 @@ static std::optional<BCLog::Level> GetLogLevel(const std::string& level_str)
307305
return BCLog::Level::Warning;
308306
} else if (level_str == "error") {
309307
return BCLog::Level::Error;
310-
} else if (level_str == "none") {
311-
return BCLog::Level::None;
312308
} else {
313309
return std::nullopt;
314310
}
@@ -396,20 +392,17 @@ std::string BCLog::Logger::GetLogPrefix(BCLog::LogFlags category, BCLog::Level l
396392
{
397393
const bool has_category{category != LogFlags::NONE};
398394

399-
if (!has_category && level == Level::None) return {};
400-
401395
// If there is no category, Info is implied
402396
if (!has_category && level == Level::Info) return {};
403397

404398
std::string s{"["};
405399
if (has_category) {
406400
s += LogCategoryToStr(category);
407-
408-
// If there is a category, Debug is implied
409-
if (level == Level::Debug) level = Level::None;
410401
}
411402

412-
if (level != Level::None) {
403+
if (!has_category || level != Level::Debug) {
404+
// If there is a category, Debug is implied, so don't add the level
405+
413406
// Only add separator if we have a category
414407
if (has_category) s += ":";
415408
s += Logger::LogLevelToStr(level);

src/logging.h

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ namespace BCLog {
7777
Info, // Default
7878
Warning,
7979
Error,
80-
None, // Internal use only
8180
};
8281
constexpr auto DEFAULT_LOG_LEVEL{Level::Debug};
8382

@@ -236,22 +235,14 @@ static inline void LogPrintf_(const std::string& logging_function, const std::st
236235
#define LogPrintLevel_(category, level, ...) LogPrintf_(__func__, __FILE__, __LINE__, category, level, __VA_ARGS__)
237236

238237
// Log unconditionally.
239-
#define LogPrintf(...) LogPrintLevel_(BCLog::LogFlags::NONE, BCLog::Level::None, __VA_ARGS__)
238+
#define LogPrintf(...) LogPrintLevel_(BCLog::LogFlags::NONE, BCLog::Level::Info, __VA_ARGS__)
240239

241240
// Log unconditionally, prefixing the output with the passed category name.
242-
#define LogPrintfCategory(category, ...) LogPrintLevel_(category, BCLog::Level::None, __VA_ARGS__)
241+
#define LogPrintfCategory(category, ...) LogPrintLevel_(category, BCLog::Level::Info, __VA_ARGS__)
243242

244243
// Use a macro instead of a function for conditional logging to prevent
245244
// evaluating arguments when logging for the category is not enabled.
246245

247-
// Log conditionally, prefixing the output with the passed category name.
248-
#define LogPrint(category, ...) \
249-
do { \
250-
if (LogAcceptCategory((category), BCLog::Level::Debug)) { \
251-
LogPrintLevel_(category, BCLog::Level::None, __VA_ARGS__); \
252-
} \
253-
} while (0)
254-
255246
// Log conditionally, prefixing the output with the passed category name and severity level.
256247
#define LogPrintLevel(category, level, ...) \
257248
do { \
@@ -260,6 +251,9 @@ static inline void LogPrintf_(const std::string& logging_function, const std::st
260251
} \
261252
} while (0)
262253

254+
// Log conditionally, prefixing the output with the passed category name.
255+
#define LogPrint(category, ...) LogPrintLevel(category, BCLog::Level::Debug, __VA_ARGS__)
256+
263257
template <typename... Args>
264258
bool error(const char* fmt, const Args&... args)
265259
{

src/test/logging_tests.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,19 @@ BOOST_FIXTURE_TEST_CASE(logging_LogPrintf_, LogSetup)
8484
{
8585
LogInstance().m_log_sourcelocations = true;
8686
LogPrintf_("fn1", "src1", 1, BCLog::LogFlags::NET, BCLog::Level::Debug, "foo1: %s\n", "bar1");
87-
LogPrintf_("fn2", "src2", 2, BCLog::LogFlags::NET, BCLog::Level::None, "foo2: %s\n", "bar2");
87+
LogPrintf_("fn2", "src2", 2, BCLog::LogFlags::NET, BCLog::Level::Info, "foo2: %s\n", "bar2");
8888
LogPrintf_("fn3", "src3", 3, BCLog::LogFlags::NONE, BCLog::Level::Debug, "foo3: %s\n", "bar3");
89-
LogPrintf_("fn4", "src4", 4, BCLog::LogFlags::NONE, BCLog::Level::None, "foo4: %s\n", "bar4");
90-
LogPrintf_("fn5", "src5", 5, BCLog::LogFlags::NONE, BCLog::Level::Info, "foo5: %s\n", "bar5");
89+
LogPrintf_("fn4", "src4", 4, BCLog::LogFlags::NONE, BCLog::Level::Info, "foo4: %s\n", "bar4");
9190
std::ifstream file{tmp_log_path};
9291
std::vector<std::string> log_lines;
9392
for (std::string log; std::getline(file, log);) {
9493
log_lines.push_back(log);
9594
}
9695
std::vector<std::string> expected = {
9796
"[src1:1] [fn1] [net] foo1: bar1",
98-
"[src2:2] [fn2] [net] foo2: bar2",
97+
"[src2:2] [fn2] [net:info] foo2: bar2",
9998
"[src3:3] [fn3] [debug] foo3: bar3",
10099
"[src4:4] [fn4] foo4: bar4",
101-
"[src5:5] [fn5] foo5: bar5",
102100
};
103101
BOOST_CHECK_EQUAL_COLLECTIONS(log_lines.begin(), log_lines.end(), expected.begin(), expected.end());
104102
}
@@ -124,7 +122,7 @@ BOOST_FIXTURE_TEST_CASE(logging_LogPrintMacros, LogSetup)
124122
"[net:info] foo8: bar8",
125123
"[net:warning] foo9: bar9",
126124
"[net:error] foo10: bar10",
127-
"[validation] foo11: bar11",
125+
"[validation:info] foo11: bar11",
128126
};
129127
BOOST_CHECK_EQUAL_COLLECTIONS(log_lines.begin(), log_lines.end(), expected.begin(), expected.end());
130128
}

0 commit comments

Comments
 (0)