/proc/self/cwd/source/server/admin/logs_handler.h
Line | Count | Source (jump to first uncovered line) |
1 | | #pragma once |
2 | | |
3 | | #include "envoy/buffer/buffer.h" |
4 | | #include "envoy/http/codes.h" |
5 | | #include "envoy/http/header_map.h" |
6 | | #include "envoy/server/admin.h" |
7 | | #include "envoy/server/instance.h" |
8 | | |
9 | | #include "source/server/admin/handler_ctx.h" |
10 | | |
11 | | #include "absl/container/flat_hash_map.h" |
12 | | #include "absl/status/statusor.h" |
13 | | #include "absl/strings/string_view.h" |
14 | | #include "absl/types/optional.h" |
15 | | #include "spdlog/spdlog.h" |
16 | | |
17 | | namespace Envoy { |
18 | | namespace Server { |
19 | | |
20 | | class LogsHandler : public HandlerContextBase, Logger::Loggable<Logger::Id::admin> { |
21 | | |
22 | | public: |
23 | | LogsHandler(Server::Instance& server); |
24 | | |
25 | | Http::Code handlerLogging(Http::ResponseHeaderMap& response_headers, Buffer::Instance& response, |
26 | | AdminStream&); |
27 | | |
28 | | Http::Code handlerReopenLogs(Http::ResponseHeaderMap& response_headers, |
29 | | Buffer::Instance& response, AdminStream&); |
30 | | |
31 | | /** |
32 | | * Returns the valid logging levels as an array of string views. |
33 | | */ |
34 | | static std::vector<absl::string_view> levelStrings(); |
35 | | |
36 | | private: |
37 | | /** |
38 | | * Attempt to change the log level of a logger or all loggers. |
39 | | * |
40 | | * @return OkStatus if there are no non-empty params, StatusCode::kInvalidArgument if |
41 | | * validation failed. |
42 | | * |
43 | | * @param params supplies the incoming endpoint query or post params. |
44 | | */ |
45 | | absl::Status changeLogLevel(Http::Utility::QueryParams& params); |
46 | | absl::Status changeLogLevelsForComponentLoggers( |
47 | | const absl::flat_hash_map<absl::string_view, spdlog::level::level_enum>& changes); |
48 | | |
49 | 0 | inline absl::StatusOr<spdlog::level::level_enum> parseLogLevel(absl::string_view level_string) { |
50 | 0 | auto level_it = log_levels_.find(level_string); |
51 | 0 | if (level_it == log_levels_.end()) { |
52 | 0 | return absl::InvalidArgumentError("unknown logger level"); |
53 | 0 | } |
54 | 0 | return level_it->second; |
55 | 0 | } |
56 | | |
57 | | // Maps level string to level enum. |
58 | | using StringViewLevelMap = absl::flat_hash_map<absl::string_view, spdlog::level::level_enum>; |
59 | | const StringViewLevelMap log_levels_; |
60 | | }; |
61 | | |
62 | | } // namespace Server |
63 | | } // namespace Envoy |