1
#pragma once
2

            
3
#include "envoy/formatter/substitution_formatter.h"
4
#include "envoy/stream_info/stream_info.h"
5

            
6
namespace Envoy {
7
namespace Extensions {
8
namespace AccessLoggers {
9
namespace Fluentd {
10

            
11
/**
12
 * A formatter for Fluentd logs
13
 */
14
class FluentdFormatter {
15
public:
16
9
  virtual ~FluentdFormatter() = default;
17

            
18
  /**
19
   * @return a vector of bytes representing the Fluentd MessagePack record
20
   */
21
  virtual std::vector<uint8_t> format(const Formatter::Context& context,
22
                                      const StreamInfo::StreamInfo& stream_info) const PURE;
23
};
24

            
25
using FluentdFormatterPtr = std::unique_ptr<FluentdFormatter>;
26

            
27
/**
28
 * A formatter for Fluentd logs. It is expecting to receive a JSON formatter, and converts the
29
 * JSON formatter message to MessagePack format.
30
 * TODO(ohadvano): Improve the formatting operation by creating a dedicated formatter that
31
 *                 will directly serialize the record to msgpack payload.
32
 */
33
class FluentdFormatterImpl : public FluentdFormatter {
34
public:
35
  FluentdFormatterImpl(Formatter::FormatterPtr json_formatter);
36

            
37
  std::vector<uint8_t> format(const Formatter::Context& context,
38
                              const StreamInfo::StreamInfo& stream_info) const override;
39

            
40
private:
41
  Formatter::FormatterPtr json_formatter_;
42
};
43

            
44
} // namespace Fluentd
45
} // namespace AccessLoggers
46
} // namespace Extensions
47
} // namespace Envoy