1
#pragma once
2

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

            
5
#include "source/common/formatter/substitution_format_string.h"
6
#include "source/common/formatter/substitution_formatter.h"
7
#include "source/extensions/access_loggers/common/file_access_log_impl.h"
8

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

            
13
template <class T, Filesystem::DestinationType destination_type>
14
AccessLog::InstanceSharedPtr
15
createStreamAccessLogInstance(const Protobuf::Message& config, AccessLog::FilterPtr&& filter,
16
                              Server::Configuration::GenericFactoryContext& context,
17
29
                              std::vector<Formatter::CommandParserPtr>&& command_parsers = {}) {
18
29
  const auto& fal_config =
19
29
      MessageUtil::downcastAndValidate<const T&>(config, context.messageValidationVisitor());
20
29
  Formatter::FormatterPtr formatter;
21
29
  if (fal_config.access_log_format_case() == T::AccessLogFormatCase::kLogFormat) {
22
4
    formatter =
23
4
        THROW_OR_RETURN_VALUE(Formatter::SubstitutionFormatStringUtils::fromProtoConfig(
24
4
                                  fal_config.log_format(), context, std::move(command_parsers)),
25
4
                              Formatter::FormatterPtr);
26
25
  } else if (fal_config.access_log_format_case() ==
27
25
             T::AccessLogFormatCase::ACCESS_LOG_FORMAT_NOT_SET) {
28
25
    formatter = THROW_OR_RETURN_VALUE(
29
25
        Formatter::HttpSubstitutionFormatUtils::defaultSubstitutionFormatter(),
30
25
        Formatter::FormatterPtr);
31
25
  }
32
29
  Filesystem::FilePathAndType file_info{destination_type, ""};
33
29
  return std::make_shared<AccessLoggers::File::FileAccessLog>(
34
29
      file_info, std::move(filter), std::move(formatter),
35
29
      context.serverFactoryContext().accessLogManager());
36
29
}
37

            
38
} // namespace AccessLoggers
39
} // namespace Extensions
40
} // namespace Envoy