29 struct NumberedLevelInfo {
36 constexpr std::array<NumberedLevelInfo, 2> numberedLogLevels = {{
44 lowerNameStr.reserve(name.
size());
46 lowerNameStr.push_back(static_cast<char>(std::tolower(
c)));
54 constexpr
StringPiece lowercasePrefix{
"loglevel::"};
56 if (lowerName.startsWith(lowercasePrefix)) {
57 lowerName.
advance(lowercasePrefix.size());
58 }
else if (lowerName.startsWith(wrapperPrefix) && lowerName.endsWith(
")")) {
59 lowerName.advance(wrapperPrefix.size());
60 lowerName.subtract(1);
63 if (lowerName ==
"uninitialized") {
65 }
else if (lowerName ==
"none") {
67 }
else if (lowerName ==
"debug" || lowerName ==
"dbg") {
69 }
else if (lowerName ==
"info") {
71 }
else if (lowerName ==
"warn" || lowerName ==
"warning") {
73 }
else if (lowerName ==
"error" || lowerName ==
"err") {
75 }
else if (lowerName ==
"critical") {
77 }
else if (lowerName ==
"dfatal") {
79 }
else if (lowerName ==
"fatal") {
81 }
else if (lowerName ==
"max" || lowerName ==
"max_level") {
85 for (
const auto&
info : numberedLogLevels) {
86 if (!lowerName.startsWith(
info.lowerPrefix)) {
89 auto remainder = lowerName.subpiece(
info.lowerPrefix.size());
90 auto level = folly::tryTo<int>(remainder).value_or(-1);
92 static_cast<unsigned int>(level) > (static_cast<uint32_t>(
info.max) -
93 static_cast<uint32_t>(
info.min))) {
94 throw std::range_error(to<string>(
95 "invalid ",
info.lowerPrefix,
" logger level: ", name.str()));
97 return info.max - level;
102 auto level = folly::to<uint32_t>(lowerName);
103 return static_cast<LogLevel>(level);
104 }
catch (
const std::exception&) {
105 throw std::range_error(
"invalid logger level: " + name.str());
111 return "UNINITIALIZED";
130 for (
const auto&
info : numberedLogLevels) {
131 if (static_cast<uint32_t>(level) <= static_cast<uint32_t>(
info.max) &&
132 static_cast<uint32_t>(level) > static_cast<uint32_t>(
info.min)) {
133 auto num =
static_cast<uint32_t>(
info.max) - static_cast<uint32_t>(level);
134 return folly::to<string>(
info.upperPrefix, num);
138 return folly::to<string>(
"LogLevel(",
static_cast<uint32_t>(level),
")");
void advance(size_type n)
constexpr size_type size() const
—— Concurrent Priority Queue Implementation ——
LogLevel stringToLogLevel(StringPiece name)
string logLevelToString(LogLevel level)
Range< const char * > StringPiece
std::ostream & operator<<(std::ostream &out, dynamic const &d)