2019-09-01 12:10:49 +00:00
|
|
|
#include <util/logging/loglevel.hpp>
|
2020-01-20 21:00:08 +00:00
|
|
|
#include <unordered_map>
|
2020-02-20 15:49:18 +00:00
|
|
|
#include <algorithm>
|
2019-06-13 13:26:34 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
std::string
|
|
|
|
LogLevelToString(LogLevel lvl)
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
switch (lvl)
|
2019-06-13 13:26:34 +00:00
|
|
|
{
|
2019-11-14 21:56:01 +00:00
|
|
|
case eLogTrace:
|
|
|
|
return "TRC";
|
2019-06-13 13:26:34 +00:00
|
|
|
case eLogDebug:
|
|
|
|
return "DBG";
|
|
|
|
case eLogInfo:
|
|
|
|
return "NFO";
|
|
|
|
case eLogWarn:
|
|
|
|
return "WRN";
|
|
|
|
case eLogError:
|
|
|
|
return "ERR";
|
|
|
|
default:
|
|
|
|
return "???";
|
|
|
|
}
|
|
|
|
}
|
2020-01-20 21:00:08 +00:00
|
|
|
|
|
|
|
std::string
|
|
|
|
LogLevelToName(LogLevel lvl)
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
switch (lvl)
|
2020-01-20 21:00:08 +00:00
|
|
|
{
|
|
|
|
case eLogTrace:
|
|
|
|
return "Trace";
|
|
|
|
case eLogDebug:
|
|
|
|
return "Debug";
|
|
|
|
case eLogInfo:
|
|
|
|
return "Info";
|
|
|
|
case eLogWarn:
|
|
|
|
return "Warn";
|
|
|
|
case eLogError:
|
|
|
|
return "Error";
|
|
|
|
case eLogNone:
|
2020-01-20 21:12:19 +00:00
|
|
|
return "None";
|
2020-01-20 21:00:08 +00:00
|
|
|
default:
|
|
|
|
return "???";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-01 19:51:15 +00:00
|
|
|
std::optional<LogLevel>
|
2020-01-20 21:00:08 +00:00
|
|
|
LogLevelFromString(std::string level)
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
std::transform(level.begin(), level.end(), level.begin(), [](const unsigned char ch) -> char {
|
|
|
|
return std::tolower(ch);
|
|
|
|
});
|
|
|
|
static const std::unordered_map<std::string, LogLevel> levels = {{"trace", eLogTrace},
|
|
|
|
{"debug", eLogDebug},
|
|
|
|
{"info", eLogInfo},
|
|
|
|
{"warn", eLogWarn},
|
|
|
|
{"error", eLogError},
|
|
|
|
{"none", eLogNone}};
|
2020-01-20 21:00:08 +00:00
|
|
|
|
|
|
|
const auto itr = levels.find(level);
|
2020-04-07 18:38:56 +00:00
|
|
|
if (itr == levels.end())
|
2020-01-20 21:00:08 +00:00
|
|
|
return {};
|
|
|
|
return itr->second;
|
|
|
|
}
|
2019-09-01 12:10:49 +00:00
|
|
|
} // namespace llarp
|