LCOV - code coverage report
Current view: top level - source/extensions/access_loggers/file - config.cc (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 20 44 45.5 %
Date: 2024-01-05 06:35:25 Functions: 3 3 100.0 %

          Line data    Source code
       1             : #include "source/extensions/access_loggers/file/config.h"
       2             : 
       3             : #include <memory>
       4             : 
       5             : #include "envoy/extensions/access_loggers/file/v3/file.pb.h"
       6             : #include "envoy/extensions/access_loggers/file/v3/file.pb.validate.h"
       7             : #include "envoy/registry/registry.h"
       8             : #include "envoy/server/filter_config.h"
       9             : 
      10             : #include "source/common/common/logger.h"
      11             : #include "source/common/config/utility.h"
      12             : #include "source/common/formatter/substitution_format_string.h"
      13             : #include "source/common/formatter/substitution_formatter.h"
      14             : #include "source/common/protobuf/protobuf.h"
      15             : #include "source/extensions/access_loggers/common/file_access_log_impl.h"
      16             : 
      17             : namespace Envoy {
      18             : namespace Extensions {
      19             : namespace AccessLoggers {
      20             : namespace File {
      21             : 
      22             : AccessLog::InstanceSharedPtr
      23             : FileAccessLogFactory::createAccessLogInstance(const Protobuf::Message& config,
      24             :                                               AccessLog::FilterPtr&& filter,
      25         168 :                                               Server::Configuration::FactoryContext& context) {
      26         168 :   const auto& fal_config = MessageUtil::downcastAndValidate<
      27         168 :       const envoy::extensions::access_loggers::file::v3::FileAccessLog&>(
      28         168 :       config, context.messageValidationVisitor());
      29         168 :   Formatter::FormatterPtr formatter;
      30             : 
      31         168 :   switch (fal_config.access_log_format_case()) {
      32           0 :   case envoy::extensions::access_loggers::file::v3::FileAccessLog::AccessLogFormatCase::kFormat:
      33           0 :     if (fal_config.format().empty()) {
      34           0 :       formatter = Formatter::HttpSubstitutionFormatUtils::defaultSubstitutionFormatter();
      35           0 :     } else {
      36           0 :       envoy::config::core::v3::SubstitutionFormatString sff_config;
      37           0 :       sff_config.mutable_text_format_source()->set_inline_string(fal_config.format());
      38           0 :       formatter = Formatter::SubstitutionFormatStringUtils::fromProtoConfig(sff_config, context);
      39           0 :     }
      40           0 :     break;
      41           0 :   case envoy::extensions::access_loggers::file::v3::FileAccessLog::AccessLogFormatCase::kJsonFormat:
      42           0 :     formatter = Formatter::SubstitutionFormatStringUtils::createJsonFormatter(
      43           0 :         fal_config.json_format(), false, false, false);
      44           0 :     break;
      45           0 :   case envoy::extensions::access_loggers::file::v3::FileAccessLog::AccessLogFormatCase::
      46           0 :       kTypedJsonFormat: {
      47           0 :     envoy::config::core::v3::SubstitutionFormatString sff_config;
      48           0 :     *sff_config.mutable_json_format() = fal_config.typed_json_format();
      49           0 :     formatter = Formatter::SubstitutionFormatStringUtils::fromProtoConfig(sff_config, context);
      50           0 :     break;
      51           0 :   }
      52           0 :   case envoy::extensions::access_loggers::file::v3::FileAccessLog::AccessLogFormatCase::kLogFormat:
      53           0 :     formatter =
      54           0 :         Formatter::SubstitutionFormatStringUtils::fromProtoConfig(fal_config.log_format(), context);
      55           0 :     break;
      56         168 :   case envoy::extensions::access_loggers::file::v3::FileAccessLog::AccessLogFormatCase::
      57         168 :       ACCESS_LOG_FORMAT_NOT_SET:
      58         168 :     formatter = Formatter::HttpSubstitutionFormatUtils::defaultSubstitutionFormatter();
      59         168 :     break;
      60         168 :   }
      61             : 
      62         168 :   Filesystem::FilePathAndType file_info{Filesystem::DestinationType::File, fal_config.path()};
      63         168 :   return std::make_shared<FileAccessLog>(file_info, std::move(filter), std::move(formatter),
      64         168 :                                          context.serverFactoryContext().accessLogManager());
      65         168 : }
      66             : 
      67         192 : ProtobufTypes::MessagePtr FileAccessLogFactory::createEmptyConfigProto() {
      68         192 :   return ProtobufTypes::MessagePtr{
      69         192 :       new envoy::extensions::access_loggers::file::v3::FileAccessLog()};
      70         192 : }
      71             : 
      72         179 : std::string FileAccessLogFactory::name() const { return "envoy.access_loggers.file"; }
      73             : 
      74             : /**
      75             :  * Static registration for the file access log. @see RegisterFactory.
      76             :  */
      77             : LEGACY_REGISTER_FACTORY(FileAccessLogFactory, AccessLog::AccessLogInstanceFactory,
      78             :                         "envoy.file_access_log");
      79             : 
      80             : } // namespace File
      81             : } // namespace AccessLoggers
      82             : } // namespace Extensions
      83             : } // namespace Envoy

Generated by: LCOV version 1.15