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