6#include <initializer_list>
11#include <boost/container/container_fwd.hpp>
13#include <userver/compiler/select.hpp>
14#include <userver/logging/fwd.hpp>
15#include <userver/utils/fast_pimpl.hpp>
17USERVER_NAMESPACE_BEGIN
34 using Value = std::variant<std::string,
int,
long,
long long,
unsigned int,
35 unsigned long,
unsigned long long,
float,
double>;
36 using Key = std::string;
37 using Pair = std::pair<Key, Value>;
47 LogExtra(
const LogExtra&);
55 LogExtra& operator=(LogExtra&&);
57 LogExtra& operator=(
const LogExtra&);
64 void Extend(std::string key, Value value,
71 void Extend(std::initializer_list<Pair> extra,
101 template <
typename Iterator>
105 for (Iterator it = first; it != last; ++it) Extend(*it, extend_type);
112 friend class impl::TagWriter;
116 const Value& GetValue(std::string_view key)
const;
118 class ProtectedValue
final {
120 ProtectedValue() =
default;
121 ProtectedValue(Value value,
bool frozen);
122 ProtectedValue(
const ProtectedValue& other) =
default;
123 ProtectedValue(ProtectedValue&& other) =
default;
125 ProtectedValue& operator=(
const ProtectedValue& other);
126 ProtectedValue& operator=(ProtectedValue&& other)
noexcept;
129 Value& GetValue() {
return value_; }
130 const Value& GetValue()
const {
return value_; }
134 bool frozen_ =
false;
137 static constexpr std::size_t kSmallVectorSize = 24;
138 static constexpr std::size_t kPimplSize = compiler::SelectSize()
141 .ForLibStdCpp64(1944)
142 .ForLibStdCpp32(1356);
143 using MapItem = std::pair<Key, ProtectedValue>;
144 using Map = boost::container::small_vector<MapItem, kSmallVectorSize>;
146 void Extend(std::string key, ProtectedValue protected_value,
150 std::pair<Key, ProtectedValue>* Find(std::string_view);
152 const std::pair<Key, ProtectedValue>* Find(std::string_view)
const;
154 utils::FastPimpl<Map, kPimplSize,
alignof(
void*)> extra_;
157extern const LogExtra kEmptyLogExtra;