1
#pragma once
2

            
3
#include "envoy/access_log/access_log.h"
4

            
5
#include "source/common/common/logger.h"
6
#include "source/extensions/common/wasm/wasm.h"
7

            
8
namespace Envoy {
9
namespace Extensions {
10
namespace AccessLoggers {
11
namespace Wasm {
12

            
13
using Common::Wasm::PluginHandleSharedPtrThreadLocal;
14
using Envoy::Extensions::Common::Wasm::PluginSharedPtr;
15

            
16
class WasmAccessLog : public AccessLog::Instance {
17
public:
18
  WasmAccessLog(Extensions::Common::Wasm::PluginConfigPtr plugin_config,
19
                AccessLog::FilterPtr filter)
20
8
      : plugin_config_(std::move(plugin_config)), filter_(std::move(filter)) {}
21

            
22
  void log(const Formatter::Context& log_context,
23
9
           const StreamInfo::StreamInfo& stream_info) override {
24
9
    if (filter_) {
25
2
      if (!filter_->evaluate(log_context, stream_info)) {
26
2
        return;
27
2
      }
28
2
    }
29

            
30
7
    if (Common::Wasm::Wasm* wasm = plugin_config_->wasm(); wasm != nullptr) {
31
5
      wasm->log(plugin_config_->plugin(), log_context, stream_info);
32
5
    }
33
7
  }
34

            
35
private:
36
  Common::Wasm::PluginConfigPtr plugin_config_;
37
  AccessLog::FilterPtr filter_;
38
};
39

            
40
} // namespace Wasm
41
} // namespace AccessLoggers
42
} // namespace Extensions
43
} // namespace Envoy