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
using LogContext = Formatter::Context;
19

            
20
class AccessLogFile {
21
public:
22
54567
  virtual ~AccessLogFile() = default;
23

            
24
  /**
25
   * Write data to the file.
26
   */
27
  virtual void write(absl::string_view) PURE;
28

            
29
  /**
30
   * Reopen the file.
31
   */
32
  virtual void reopen() PURE;
33

            
34
  /**
35
   * Synchronously flush all pending data to disk.
36
   */
37
  virtual void flush() PURE;
38
};
39

            
40
using AccessLogFileSharedPtr = std::shared_ptr<AccessLogFile>;
41

            
42
class AccessLogManager {
43
public:
44
52958
  virtual ~AccessLogManager() = default;
45

            
46
  /**
47
   * Reopen all of the access log files.
48
   */
49
  virtual void reopen() PURE;
50

            
51
  /**
52
   * Create a new access log file managed by the access log manager.
53
   * @param file_info specifies the file to create/open.
54
   * @return the opened file or an error status.
55
   */
56
  virtual absl::StatusOr<AccessLogFileSharedPtr>
57
  createAccessLog(const Envoy::Filesystem::FilePathAndType& file_info) PURE;
58
};
59

            
60
using AccessLogManagerPtr = std::unique_ptr<AccessLogManager>;
61
using AccessLogType = envoy::data::accesslog::v3::AccessLogType;
62

            
63
/**
64
 * Interface for access log filters.
65
 */
66
class Filter {
67
public:
68
9521
  virtual ~Filter() = default;
69

            
70
  /**
71
   * Evaluate whether an access log should be written based on request and response data.
72
   * @return TRUE if the log should be written.
73
   */
74
  virtual bool evaluate(const LogContext& context, const StreamInfo::StreamInfo& info) const PURE;
75
};
76
using FilterPtr = std::unique_ptr<Filter>;
77

            
78
/**
79
 * Interface for access log instances.
80
 */
81
class Instance {
82
public:
83
23532
  virtual ~Instance() = 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 LogContext& context, const StreamInfo::StreamInfo& stream_info) PURE;
92
};
93
using InstanceSharedPtr = std::shared_ptr<Instance>;
94
using InstanceSharedPtrVector = std::vector<InstanceSharedPtr>;
95

            
96
} // namespace AccessLog
97
} // namespace Envoy