Skip to content

Commit

Permalink
feat universal: amend log format error message
Browse files Browse the repository at this point in the history
Tests: протестировано CI
Fixes: https://github.com/userver-framework/userver/pull/691/files
Co-authored-by: Timur Khanipov <khanipov@gmail.com>
commit_hash:cdf0d6c2b94c6d4c776e01dee67c79b11ca5dfea
  • Loading branch information
apolukhin committed Dec 23, 2024
1 parent d837266 commit 8cc25d8
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions universal/src/logging/format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@
#include <fmt/format.h>

#include <userver/utils/assert.hpp>
#include <userver/utils/trivial_map.hpp>

USERVER_NAMESPACE_BEGIN

namespace logging {

Format FormatFromString(std::string_view format_str) {
if (format_str == "tskv") {
return Format::kTskv;
}

if (format_str == "ltsv") {
return Format::kLtsv;
}
namespace {
constexpr utils::TrivialBiMap kLogFormats = [](auto selector) {
return selector().Case("tskv", Format::kTskv).Case("ltsv", Format::kLtsv).Case("raw", Format::kRaw);
};

if (format_str == "raw") {
return Format::kRaw;
}
}

UINVARIANT(false, fmt::format("Unknown logging format '{}' (must be one of 'tskv', 'ltsv')", format_str));
Format FormatFromString(std::string_view format_str) {
const auto result = kLogFormats.TryFindByFirst(format_str);
UINVARIANT(
result, fmt::format("Unknown logging format '{}' (must be one of {})", format_str, kLogFormats.DescribeFirst())
);
return *result;
}

} // namespace logging
Expand Down

0 comments on commit 8cc25d8

Please sign in to comment.