Simplify BCLog::Level enum class and LogLevelToStr() function

- simplify the BCLog::Level enum class (and future changes to it) by
  only setting the value of the first enumerator

- move the BCLog::Level:None enumerator to the end of the BCLog::Level
  enum class and LogLevelToStr() member function, as the None enumerator
  is only used internally, and by being the highest BCLog::Level value it
  can be used to iterate over the enumerators

- replace the unused BCLog::Level:None string "none" with an empty string
  as the case will never be hit

- add documentation
This commit is contained in:
Jon Atack 2022-05-31 21:49:55 +02:00
parent a5d5569535
commit f1379aeca9
2 changed files with 9 additions and 9 deletions

View File

@ -135,7 +135,7 @@ struct CLogCategoryDesc {
const CLogCategoryDesc LogCategories[] = const CLogCategoryDesc LogCategories[] =
{ {
{BCLog::NONE, "0"}, {BCLog::NONE, "0"},
{BCLog::NONE, "none"}, {BCLog::NONE, ""},
{BCLog::NET, "net"}, {BCLog::NET, "net"},
{BCLog::TOR, "tor"}, {BCLog::TOR, "tor"},
{BCLog::MEMPOOL, "mempool"}, {BCLog::MEMPOOL, "mempool"},
@ -187,8 +187,6 @@ bool GetLogCategory(BCLog::LogFlags& flag, const std::string& str)
std::string LogLevelToStr(BCLog::Level level) std::string LogLevelToStr(BCLog::Level level)
{ {
switch (level) { switch (level) {
case BCLog::Level::None:
return "none";
case BCLog::Level::Debug: case BCLog::Level::Debug:
return "debug"; return "debug";
case BCLog::Level::Info: case BCLog::Level::Info:
@ -197,6 +195,8 @@ std::string LogLevelToStr(BCLog::Level level)
return "warning"; return "warning";
case BCLog::Level::Error: case BCLog::Level::Error:
return "error"; return "error";
case BCLog::Level::None:
return "";
} }
assert(false); assert(false);
} }
@ -206,7 +206,7 @@ std::string LogCategoryToStr(BCLog::LogFlags category)
// Each log category string representation should sync with LogCategories // Each log category string representation should sync with LogCategories
switch (category) { switch (category) {
case BCLog::LogFlags::NONE: case BCLog::LogFlags::NONE:
return "none"; return "";
case BCLog::LogFlags::NET: case BCLog::LogFlags::NET:
return "net"; return "net";
case BCLog::LogFlags::TOR: case BCLog::LogFlags::TOR:

View File

@ -68,11 +68,11 @@ namespace BCLog {
ALL = ~(uint32_t)0, ALL = ~(uint32_t)0,
}; };
enum class Level { enum class Level {
Debug = 0, Debug = 0, // High-volume or detailed logging for development/debugging
None = 1, Info, // Default
Info = 2, Warning,
Warning = 3, Error,
Error = 4, None, // Internal use only
}; };
class Logger class Logger