/proc/self/cwd/source/server/options_impl_base.cc
Line | Count | Source (jump to first uncovered line) |
1 | | #include "source/server/options_impl_base.h" |
2 | | |
3 | | #include <chrono> |
4 | | #include <cstdint> |
5 | | #include <iostream> |
6 | | #include <string> |
7 | | |
8 | | #include "envoy/admin/v3/server_info.pb.h" |
9 | | |
10 | | #include "source/common/common/fmt.h" |
11 | | #include "source/common/common/logger.h" |
12 | | #include "source/common/common/macros.h" |
13 | | #include "source/common/protobuf/utility.h" |
14 | | #include "source/common/stats/tag_utility.h" |
15 | | #include "source/common/version/version.h" |
16 | | |
17 | | #include "absl/strings/str_replace.h" |
18 | | #include "absl/strings/str_split.h" |
19 | | #include "absl/strings/string_view.h" |
20 | | #include "spdlog/spdlog.h" |
21 | | |
22 | | namespace Envoy { |
23 | | |
24 | | absl::StatusOr<spdlog::level::level_enum> |
25 | 0 | OptionsImplBase::parseAndValidateLogLevel(absl::string_view log_level) { |
26 | 0 | if (log_level == "warn") { |
27 | 0 | return spdlog::level::level_enum::warn; |
28 | 0 | } |
29 | | |
30 | 0 | size_t level_to_use = std::numeric_limits<size_t>::max(); |
31 | 0 | for (size_t i = 0; i < ARRAY_SIZE(spdlog::level::level_string_views); i++) { |
32 | 0 | spdlog::string_view_t spd_log_level = spdlog::level::level_string_views[i]; |
33 | 0 | if (log_level == absl::string_view(spd_log_level.data(), spd_log_level.size())) { |
34 | 0 | level_to_use = i; |
35 | 0 | break; |
36 | 0 | } |
37 | 0 | } |
38 | |
|
39 | 0 | if (level_to_use == std::numeric_limits<size_t>::max()) { |
40 | 0 | return absl::InvalidArgumentError( |
41 | 0 | fmt::format("error: invalid log level specified '{}'", log_level)); |
42 | 0 | } |
43 | 0 | return static_cast<spdlog::level::level_enum>(level_to_use); |
44 | 0 | } |
45 | | |
46 | 0 | absl::Status OptionsImplBase::setLogLevel(absl::string_view log_level) { |
47 | 0 | auto status_or_level = parseAndValidateLogLevel(log_level); |
48 | 0 | if (!status_or_level.status().ok()) { |
49 | 0 | return status_or_level.status(); |
50 | 0 | } |
51 | 0 | setLogLevel(status_or_level.value()); |
52 | 0 | return absl::OkStatus(); |
53 | 0 | } |
54 | | |
55 | 0 | uint32_t OptionsImplBase::count() const { return count_; } |
56 | | |
57 | 0 | void OptionsImplBase::disableExtensions(const std::vector<std::string>& names) { |
58 | 0 | for (const auto& name : names) { |
59 | 0 | const std::vector<absl::string_view> parts = absl::StrSplit(name, absl::MaxSplits('/', 1)); |
60 | |
|
61 | 0 | if (parts.size() != 2) { |
62 | 0 | ENVOY_LOG_MISC(warn, "failed to disable invalid extension name '{}'", name); |
63 | 0 | continue; |
64 | 0 | } |
65 | | |
66 | 0 | if (Registry::FactoryCategoryRegistry::disableFactory(parts[0], parts[1])) { |
67 | 0 | ENVOY_LOG_MISC(info, "disabled extension '{}'", name); |
68 | 0 | } else { |
69 | 0 | ENVOY_LOG_MISC(warn, "failed to disable unknown extension '{}'", name); |
70 | 0 | } |
71 | 0 | } |
72 | 0 | } |
73 | | |
74 | | } // namespace Envoy |