/proc/self/cwd/envoy/access_log/access_log.h
Line | Count | Source |
1 | | #pragma once |
2 | | |
3 | | #include <memory> |
4 | | #include <string> |
5 | | |
6 | | #include "envoy/common/pure.h" |
7 | | #include "envoy/data/accesslog/v3/accesslog.pb.h" |
8 | | #include "envoy/filesystem/filesystem.h" |
9 | | #include "envoy/formatter/http_formatter_context.h" |
10 | | #include "envoy/http/header_map.h" |
11 | | #include "envoy/stream_info/stream_info.h" |
12 | | |
13 | | #include "source/common/protobuf/protobuf.h" |
14 | | |
15 | | namespace Envoy { |
16 | | namespace AccessLog { |
17 | | |
18 | | class AccessLogFile { |
19 | | public: |
20 | 30.1k | virtual ~AccessLogFile() = default; |
21 | | |
22 | | /** |
23 | | * Write data to the file. |
24 | | */ |
25 | | virtual void write(absl::string_view) PURE; |
26 | | |
27 | | /** |
28 | | * Reopen the file. |
29 | | */ |
30 | | virtual void reopen() PURE; |
31 | | |
32 | | /** |
33 | | * Synchronously flush all pending data to disk. |
34 | | */ |
35 | | virtual void flush() PURE; |
36 | | }; |
37 | | |
38 | | using AccessLogFileSharedPtr = std::shared_ptr<AccessLogFile>; |
39 | | |
40 | | class AccessLogManager { |
41 | | public: |
42 | 39.4k | virtual ~AccessLogManager() = default; |
43 | | |
44 | | /** |
45 | | * Reopen all of the access log files. |
46 | | */ |
47 | | virtual void reopen() PURE; |
48 | | |
49 | | /** |
50 | | * Create a new access log file managed by the access log manager. |
51 | | * @param file_info specifies the file to create/open. |
52 | | * @return the opened file. |
53 | | */ |
54 | | virtual AccessLogFileSharedPtr |
55 | | createAccessLog(const Envoy::Filesystem::FilePathAndType& file_info) PURE; |
56 | | }; |
57 | | |
58 | | using AccessLogManagerPtr = std::unique_ptr<AccessLogManager>; |
59 | | using AccessLogType = envoy::data::accesslog::v3::AccessLogType; |
60 | | |
61 | | /** |
62 | | * Templated interface for access log filters. |
63 | | */ |
64 | | template <class Context> class FilterBase { |
65 | | public: |
66 | 68.6k | virtual ~FilterBase() = default; |
67 | | |
68 | | /** |
69 | | * Evaluate whether an access log should be written based on request and response data. |
70 | | * @return TRUE if the log should be written. |
71 | | */ |
72 | | virtual bool evaluate(const Context& context, const StreamInfo::StreamInfo& info) const PURE; |
73 | | }; |
74 | | template <class Context> using FilterBasePtr = std::unique_ptr<FilterBase<Context>>; |
75 | | |
76 | | /** |
77 | | * Templated interface for access log instances. |
78 | | * TODO(wbpcode): refactor existing access log instances and related other interfaces to use this |
79 | | * interface. See https://github.com/envoyproxy/envoy/issues/28773. |
80 | | */ |
81 | | template <class Context> class InstanceBase { |
82 | | public: |
83 | 9.97k | virtual ~InstanceBase() = default; |
84 | | |
85 | | /** |
86 | | * Log a completed request. |
87 | | * @param context supplies the context for the log. |
88 | | * @param stream_info supplies additional information about the request not |
89 | | * contained in the request headers. |
90 | | */ |
91 | | virtual void log(const Context& context, const StreamInfo::StreamInfo& stream_info) PURE; |
92 | | }; |
93 | | template <class Context> using InstanceBaseSharedPtr = std::shared_ptr<InstanceBase<Context>>; |
94 | | |
95 | | /** |
96 | | * Interface for HTTP access log filters. |
97 | | */ |
98 | | using Filter = FilterBase<Formatter::HttpFormatterContext>; |
99 | | using FilterPtr = std::unique_ptr<Filter>; |
100 | | |
101 | | /** |
102 | | * Abstract access logger for HTTP requests and TCP connections. |
103 | | */ |
104 | | using Instance = InstanceBase<Formatter::HttpFormatterContext>; |
105 | | using InstanceSharedPtr = std::shared_ptr<Instance>; |
106 | | |
107 | | } // namespace AccessLog |
108 | | } // namespace Envoy |