Skip to content

Commit

Permalink
access log: clean up some unnecessary code (envoyproxy#34827)
Browse files Browse the repository at this point in the history
Signed-off-by: wbpcode <[email protected]>
Co-authored-by: wbpcode <[email protected]>
  • Loading branch information
wbpcode and wbpcode authored Jun 21, 2024
1 parent 7e5a34d commit b2c9775
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 47 deletions.
34 changes: 8 additions & 26 deletions source/common/formatter/stream_info_formatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ const StreamInfoFormatterProviderLookupTable& getKnownStreamInfoFormatterProvide
* which it was initialized.
*/
template <class FormatterContext>
class CommonPlainStringFormatterBase : public FormatterProviderBase<FormatterContext> {
class PlainStringFormatterBase : public FormatterProviderBase<FormatterContext> {
public:
CommonPlainStringFormatterBase(const std::string& str) { str_.set_string_value(str); }
PlainStringFormatterBase(const std::string& str) { str_.set_string_value(str); }

// FormatterProviderBase
absl::optional<std::string> formatWithContext(const FormatterContext&,
Expand All @@ -276,19 +276,13 @@ class CommonPlainStringFormatterBase : public FormatterProviderBase<FormatterCon
ProtobufWkt::Value str_;
};

template <class FormatterContext>
class PlainStringFormatterBase : public CommonPlainStringFormatterBase<FormatterContext> {
public:
using CommonPlainStringFormatterBase<FormatterContext>::CommonPlainStringFormatterBase;
};

/**
* FormatterProvider for numbers.
*/
template <class FormatterContext>
class CommonPlainNumberFormatterBase : public FormatterProviderBase<FormatterContext> {
class PlainNumberFormatterBase : public FormatterProviderBase<FormatterContext> {
public:
CommonPlainNumberFormatterBase(double num) { num_.set_number_value(num); }
PlainNumberFormatterBase(double num) { num_.set_number_value(num); }

// FormatterProviderBase
absl::optional<std::string> formatWithContext(const FormatterContext&,
Expand All @@ -305,20 +299,14 @@ class CommonPlainNumberFormatterBase : public FormatterProviderBase<FormatterCon
ProtobufWkt::Value num_;
};

template <class FormatterContext>
class PlainNumberFormatterBase : public CommonPlainNumberFormatterBase<FormatterContext> {
public:
using CommonPlainNumberFormatterBase<FormatterContext>::CommonPlainNumberFormatterBase;
};

/**
* FormatterProvider based on StreamInfo fields.
*/
template <class FormatterContext>
class CommonStreamInfoFormatterBase : public FormatterProviderBase<FormatterContext> {
class StreamInfoFormatterBase : public FormatterProviderBase<FormatterContext> {
public:
CommonStreamInfoFormatterBase(const std::string& command, const std::string& sub_command = "",
absl::optional<size_t> max_length = absl::nullopt) {
StreamInfoFormatterBase(const std::string& command, const std::string& sub_command = "",
absl::optional<size_t> max_length = absl::nullopt) {

const auto& formatters = getKnownStreamInfoFormatterProviders();

Expand All @@ -337,7 +325,7 @@ class CommonStreamInfoFormatterBase : public FormatterProviderBase<FormatterCont
formatter_ = (*it).second.second(sub_command, max_length);
}

CommonStreamInfoFormatterBase(StreamInfoFormatterProviderPtr formatter)
StreamInfoFormatterBase(StreamInfoFormatterProviderPtr formatter)
: formatter_(std::move(formatter)) {}

// FormatterProvider
Expand All @@ -356,12 +344,6 @@ class CommonStreamInfoFormatterBase : public FormatterProviderBase<FormatterCont
StreamInfoFormatterProviderPtr formatter_;
};

template <class FormatterContext>
class StreamInfoFormatterBase : public CommonStreamInfoFormatterBase<FormatterContext> {
public:
using CommonStreamInfoFormatterBase<FormatterContext>::CommonStreamInfoFormatterBase;
};

// Aliases for backward compatibility.
using PlainNumberFormatter = PlainNumberFormatterBase<HttpFormatterContext>;
using PlainStringFormatter = PlainStringFormatterBase<HttpFormatterContext>;
Expand Down
29 changes: 8 additions & 21 deletions source/common/formatter/substitution_formatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,17 @@ inline constexpr absl::string_view DefaultUnspecifiedValueStringView = "-";
/**
* Composite formatter implementation.
*/
template <class FormatterContext>
class CommonFormatterBaseImpl : public FormatterBase<FormatterContext> {
template <class FormatterContext> class FormatterBaseImpl : public FormatterBase<FormatterContext> {
public:
using CommandParsers = std::vector<CommandParserBasePtr<FormatterContext>>;

CommonFormatterBaseImpl(const std::string& format, bool omit_empty_values = false)
FormatterBaseImpl(const std::string& format, bool omit_empty_values = false)
: empty_value_string_(omit_empty_values ? absl::string_view{}
: DefaultUnspecifiedValueStringView) {
providers_ = SubstitutionFormatParser::parse<FormatterContext>(format);
}
CommonFormatterBaseImpl(const std::string& format, bool omit_empty_values,
const CommandParsers& command_parsers)
FormatterBaseImpl(const std::string& format, bool omit_empty_values,
const CommandParsers& command_parsers)
: empty_value_string_(omit_empty_values ? absl::string_view{}
: DefaultUnspecifiedValueStringView) {
providers_ = SubstitutionFormatParser::parse<FormatterContext>(format, command_parsers);
Expand All @@ -169,12 +168,6 @@ class CommonFormatterBaseImpl : public FormatterBase<FormatterContext> {
std::vector<FormatterProviderBasePtr<FormatterContext>> providers_;
};

template <class FormatterContext>
class FormatterBaseImpl : public CommonFormatterBaseImpl<FormatterContext> {
public:
using CommonFormatterBaseImpl<FormatterContext>::CommonFormatterBaseImpl;
};

// Helper classes for StructFormatter::StructFormatMapVisitor.
template <class... Ts> struct StructFormatMapVisitorHelper : Ts... { using Ts::operator()...; };
template <class... Ts> StructFormatMapVisitorHelper(Ts...) -> StructFormatMapVisitorHelper<Ts...>;
Expand Down Expand Up @@ -382,13 +375,13 @@ template <class FormatterContext>
using StructFormatterBasePtr = std::unique_ptr<StructFormatterBase<FormatterContext>>;

template <class FormatterContext>
class CommonJsonFormatterBaseImpl : public FormatterBase<FormatterContext> {
class JsonFormatterBaseImpl : public FormatterBase<FormatterContext> {
public:
using CommandParsers = std::vector<CommandParserBasePtr<FormatterContext>>;

CommonJsonFormatterBaseImpl(const ProtobufWkt::Struct& format_mapping, bool preserve_types,
bool omit_empty_values, bool sort_properties,
const CommandParsers& commands = {})
JsonFormatterBaseImpl(const ProtobufWkt::Struct& format_mapping, bool preserve_types,
bool omit_empty_values, bool sort_properties,
const CommandParsers& commands = {})
: struct_formatter_(format_mapping, preserve_types, omit_empty_values, commands),
sort_properties_(sort_properties) {}

Expand Down Expand Up @@ -416,12 +409,6 @@ class CommonJsonFormatterBaseImpl : public FormatterBase<FormatterContext> {
const bool sort_properties_;
};

template <class FormatterContext>
class JsonFormatterBaseImpl : public CommonJsonFormatterBaseImpl<FormatterContext> {
public:
using CommonJsonFormatterBaseImpl<FormatterContext>::CommonJsonFormatterBaseImpl;
};

using StructFormatter = StructFormatterBase<HttpFormatterContext>;
using StructFormatterPtr = std::unique_ptr<StructFormatter>;

Expand Down

0 comments on commit b2c9775

Please sign in to comment.