forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.cc
58 lines (49 loc) · 2.02 KB
/
utils.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
#include "source/server/utils.h"
#include "envoy/common/exception.h"
#include "source/common/common/assert.h"
namespace Envoy {
namespace Server {
namespace Utility {
envoy::admin::v3::ServerInfo::State serverState(Init::Manager::State state,
bool health_check_failed) {
switch (state) {
case Init::Manager::State::Uninitialized:
return envoy::admin::v3::ServerInfo::PRE_INITIALIZING;
case Init::Manager::State::Initializing:
return envoy::admin::v3::ServerInfo::INITIALIZING;
case Init::Manager::State::Initialized:
return health_check_failed ? envoy::admin::v3::ServerInfo::DRAINING
: envoy::admin::v3::ServerInfo::LIVE;
}
IS_ENVOY_BUG("unexpected server state enum");
return envoy::admin::v3::ServerInfo::PRE_INITIALIZING;
}
absl::Status assertExclusiveLogFormatMethod(
const Options& options,
const envoy::config::bootstrap::v3::Bootstrap::ApplicationLogConfig& application_log_config) {
if (options.logFormatSet() && application_log_config.has_log_format()) {
return absl::InvalidArgumentError(
"Only one of ApplicationLogConfig.log_format or CLI option --log-format can be specified.");
}
return absl::OkStatus();
}
absl::Status maybeSetApplicationLogFormat(
const envoy::config::bootstrap::v3::Bootstrap::ApplicationLogConfig& application_log_config) {
if (!application_log_config.has_log_format()) {
return absl::OkStatus();
}
if (application_log_config.log_format().has_text_format()) {
Logger::Registry::setLogFormat(application_log_config.log_format().text_format());
} else if (application_log_config.log_format().has_json_format()) {
const auto status =
Logger::Registry::setJsonLogFormat(application_log_config.log_format().json_format());
if (!status.ok()) {
return absl::InvalidArgumentError(
fmt::format("setJsonLogFormat error: {}", status.ToString()));
}
}
return absl::OkStatus();
}
} // namespace Utility
} // namespace Server
} // namespace Envoy