mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-10-31 09:20:21 +00:00
7caa87862e
All #ifndef guards on headers have been removed, I think, in favor of #pragma once Headers are now included as `#include "filename"` if the included file resides in the same directory as the file including it, or any subdirectory therein. Otherwise they are included as `#include <project/top/dir/relative/path/filename>` The above does not include system/os headers.
69 lines
1.4 KiB
C++
69 lines
1.4 KiB
C++
#include "loglevel.hpp"
|
|
#include <unordered_map>
|
|
#include <algorithm>
|
|
|
|
namespace llarp
|
|
{
|
|
std::string
|
|
LogLevelToString(LogLevel lvl)
|
|
{
|
|
switch (lvl)
|
|
{
|
|
case eLogTrace:
|
|
return "TRC";
|
|
case eLogDebug:
|
|
return "DBG";
|
|
case eLogInfo:
|
|
return "NFO";
|
|
case eLogWarn:
|
|
return "WRN";
|
|
case eLogError:
|
|
return "ERR";
|
|
default:
|
|
return "???";
|
|
}
|
|
}
|
|
|
|
std::string
|
|
LogLevelToName(LogLevel lvl)
|
|
{
|
|
switch (lvl)
|
|
{
|
|
case eLogTrace:
|
|
return "Trace";
|
|
case eLogDebug:
|
|
return "Debug";
|
|
case eLogInfo:
|
|
return "Info";
|
|
case eLogWarn:
|
|
return "Warn";
|
|
case eLogError:
|
|
return "Error";
|
|
case eLogNone:
|
|
return "None";
|
|
default:
|
|
return "???";
|
|
}
|
|
}
|
|
|
|
std::optional<LogLevel>
|
|
LogLevelFromString(std::string level)
|
|
{
|
|
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}};
|
|
|
|
const auto itr = levels.find(level);
|
|
if (itr == levels.end())
|
|
return {};
|
|
return itr->second;
|
|
}
|
|
} // namespace llarp
|