Skip to content

Commit 6a6e036

Browse files
committed
feat universal: cleanup logging helpers
Tests: протестировано CI commit_hash:557e0f764c1c49bfe9437acd0963cb34508ffe0e
1 parent b6b02fe commit 6a6e036

3 files changed

Lines changed: 11 additions & 18 deletions

File tree

core/src/tracing/span.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ void Span::Impl::PutIntoLogger(logging::impl::TagWriter writer) && {
197197
}
198198

199199
void Span::Impl::LogTo(logging::impl::TagWriter writer) const {
200-
writer.ExtendLogExtra(log_extra_inheritable_);
200+
writer.PutLogExtra(log_extra_inheritable_);
201201

202202
if (const auto span_id = GetSpanIdForChildLogs()) {
203203
writer.PutTag(kTraceIdTag, GetTraceId());

universal/include/userver/logging/impl/tag_writer.hpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,11 @@ class TagWriter {
5050
// The tags must not be duplicated in other Put* calls.
5151
void PutLogExtra(const LogExtra& extra);
5252

53-
// Copies the tags to the internal LogExtra. They will be deduplicated
54-
// automatically.
55-
void ExtendLogExtra(const LogExtra& extra);
56-
5753
private:
5854
friend class logging::LogHelper;
5955

6056
explicit TagWriter(LogHelper& lh) noexcept;
6157

62-
void PutKey(TagKey key);
63-
void PutKey(RuntimeTagKey key);
64-
65-
void MarkValueEnd() noexcept;
66-
6758
LogHelper& lh_;
6859
};
6960

@@ -91,12 +82,20 @@ consteval TagKey::TagKey(const StringType& escaped_key)
9182

9283
template <typename T>
9384
void TagWriter::PutTag(TagKey key, const T& value) {
94-
lh_.PutTag(key.GetEscapedKey(), value);
85+
if constexpr (std::is_convertible_v<T, std::string_view>) {
86+
lh_.PutSwTag(key.GetEscapedKey(), value);
87+
} else {
88+
lh_.PutTag(key.GetEscapedKey(), value);
89+
}
9590
}
9691

9792
template <typename T>
9893
void TagWriter::PutTag(RuntimeTagKey key, const T& value) {
99-
lh_.PutTag(key.GetUnescapedKey(), std::variant{value});
94+
if constexpr (std::is_convertible_v<T, std::string_view>) {
95+
lh_.PutSwTag(key.GetUnescapedKey(), value);
96+
} else {
97+
lh_.PutTag(key.GetUnescapedKey(), value);
98+
}
10099
}
101100

102101
} // namespace logging::impl

universal/src/logging/impl/tag_writer.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ void TagWriter::PutLogExtra(const LogExtra& extra) {
3737
}
3838
}
3939

40-
void TagWriter::ExtendLogExtra(const LogExtra& extra) {
41-
for (const auto& item : *extra.extra_) {
42-
PutTag(RuntimeTagKey{item.first}, item.second.GetValue());
43-
}
44-
}
45-
4640
void TagWriter::PutTag(RuntimeTagKey key, std::string_view value) { lh_.PutSwTag(key.GetUnescapedKey(), value); }
4741

4842
TagWriter::TagWriter(LogHelper& lh) noexcept : lh_(lh) {}

0 commit comments

Comments
 (0)