-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Expand file tree
/
Copy pathlogs_handler.h
More file actions
64 lines (51 loc) · 2.01 KB
/
logs_handler.h
File metadata and controls
64 lines (51 loc) · 2.01 KB
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
#pragma once
#include "envoy/buffer/buffer.h"
#include "envoy/http/codes.h"
#include "envoy/http/header_map.h"
#include "envoy/server/admin.h"
#include "envoy/server/instance.h"
#include "source/common/common/logger.h"
#include "source/server/admin/handler_ctx.h"
#include "absl/container/flat_hash_map.h"
#include "absl/status/statusor.h"
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "spdlog/spdlog.h"
namespace Envoy {
namespace Server {
class LogsHandler : public HandlerContextBase, Logger::Loggable<Logger::Id::admin> {
public:
LogsHandler(Server::Instance& server);
Http::Code handlerLogging(Http::ResponseHeaderMap& response_headers, Buffer::Instance& response,
AdminStream&);
Http::Code handlerReopenLogs(Http::ResponseHeaderMap& response_headers,
Buffer::Instance& response, AdminStream&);
/**
* Returns the valid logging levels as an array of string views.
*/
static std::vector<absl::string_view> levelStrings();
private:
/**
* Attempt to change the log level of a logger or all loggers.
*
* @return OkStatus if there are no non-empty params, StatusCode::kInvalidArgument if
* validation failed.
*
* @param params supplies the incoming endpoint query or post params.
*/
absl::Status changeLogLevel(Http::Utility::QueryParamsMulti& params);
absl::Status changeLogLevelsForComponentLoggers(
const absl::flat_hash_map<absl::string_view, spdlog::level::level_enum>& changes);
inline absl::StatusOr<spdlog::level::level_enum> parseLogLevel(absl::string_view level_string) {
auto level_it = log_levels_.find(level_string);
if (level_it == log_levels_.end()) {
return absl::InvalidArgumentError("unknown logger level");
}
return level_it->second;
}
// Maps level string to level enum.
using StringViewLevelMap = absl::flat_hash_map<absl::string_view, spdlog::level::level_enum>;
const StringViewLevelMap log_levels_;
};
} // namespace Server
} // namespace Envoy