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
14
OptionsImplBase::parseAndValidateLogLevel(absl::string_view log_level) {
26
14
  if (log_level == "warn") {
27
1
    return spdlog::level::level_enum::warn;
28
1
  }
29

            
30
13
  size_t level_to_use = std::numeric_limits<size_t>::max();
31
54
  for (size_t i = 0; i < ARRAY_SIZE(spdlog::level::level_string_views); i++) {
32
50
    spdlog::string_view_t spd_log_level = spdlog::level::level_string_views[i];
33
50
    if (log_level == absl::string_view(spd_log_level.data(), spd_log_level.size())) {
34
9
      level_to_use = i;
35
9
      break;
36
9
    }
37
50
  }
38

            
39
13
  if (level_to_use == std::numeric_limits<size_t>::max()) {
40
4
    return absl::InvalidArgumentError(
41
4
        fmt::format("error: invalid log level specified '{}'", log_level));
42
4
  }
43
9
  return static_cast<spdlog::level::level_enum>(level_to_use);
44
13
}
45

            
46
absl::Status OptionsImplBase::setLogLevel(absl::string_view log_level) {
47
  auto status_or_level = parseAndValidateLogLevel(log_level);
48
  if (!status_or_level.status().ok()) {
49
    return status_or_level.status();
50
  }
51
  setLogLevel(status_or_level.value());
52
  return absl::OkStatus();
53
}
54

            
55
1
uint32_t OptionsImplBase::count() const { return count_; }
56

            
57
45
void OptionsImplBase::disableExtensions(const std::vector<std::string>& names) {
58
45
  for (const auto& name : names) {
59
1
    const std::vector<absl::string_view> parts = absl::StrSplit(name, absl::MaxSplits('/', 1));
60

            
61
1
    if (parts.size() != 2) {
62
      ENVOY_LOG_MISC(warn, "failed to disable invalid extension name '{}'", name);
63
      continue;
64
    }
65

            
66
1
    if (Registry::FactoryCategoryRegistry::disableFactory(parts[0], parts[1])) {
67
1
      ENVOY_LOG_MISC(info, "disabled extension '{}'", name);
68
1
    } else {
69
      ENVOY_LOG_MISC(warn, "failed to disable unknown extension '{}'", name);
70
    }
71
1
  }
72
45
}
73

            
74
} // namespace Envoy