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
38 using Value = std::variant<std::string,
int,
long,
long long,
unsigned int,
39 unsigned long,
unsigned long long,
float,
double>;
40 using Key = std::string;
41 using Pair = std::pair<Key, Value>;
51 LogExtra(
const LogExtra&);
59 LogExtra& operator=(LogExtra&&);
61 LogExtra& operator=(
const LogExtra&);
68 void Extend(std::string key, Value value,
75 void Extend(std::initializer_list<Pair> extra,
105 template <
typename Iterator>
109 for (Iterator it = first; it != last; ++it) Extend(*it, extend_type);
116 friend class impl::TagWriter;
121 const Value& GetValue(std::string_view key)
const;
123 class ProtectedValue
final {
125 ProtectedValue() =
default;
126 ProtectedValue(Value value,
bool frozen);
127 ProtectedValue(
const ProtectedValue& other) =
default;
128 ProtectedValue(ProtectedValue&& other) =
default;
130 ProtectedValue& operator=(
const ProtectedValue& other);
131 ProtectedValue& operator=(ProtectedValue&& other)
noexcept;
133 bool IsFrozen()
const;
135 Value& GetValue() {
return value_; }
136 const Value& GetValue()
const {
return value_; }
137 void AssignIgnoringFrozenness(ProtectedValue other);
141 bool frozen_ =
false;
144 static constexpr std::size_t kSmallVectorSize = 24;
145 static constexpr std::size_t kPimplSize = compiler::SelectSize()
148 .ForLibStdCpp64(1944)
149 .ForLibStdCpp32(1356);
150 using MapItem = std::pair<Key, ProtectedValue>;
151 using Map = boost::container::small_vector<MapItem, kSmallVectorSize>;
153 void Extend(std::string key, ProtectedValue protected_value,
158 std::pair<Key, ProtectedValue>* Find(std::string_view);
160 const std::pair<Key, ProtectedValue>* Find(std::string_view)
const;
162 utils::FastPimpl<Map, kPimplSize,
alignof(
void*)> extra_;
165extern const LogExtra kEmptyLogExtra;