22#include "util/Assert.hpp"
23#include "util/newconfig/ConfigDefinition.hpp"
25#include <boost/algorithm/string/predicate.hpp>
26#include <boost/json.hpp>
27#include <boost/json/conversion.hpp>
28#include <boost/json/value.hpp>
29#include <boost/uuid/uuid.hpp>
30#include <boost/uuid/uuid_io.hpp>
53 using TagType = std::atomic_uint64_t;
63 using TagType = boost::uuids::uuid;
106template <
typename Generator>
108 using ParentType = std::optional<std::reference_wrapper<BaseTagDecorator const>>;
109 using TagType =
typename Generator::TagType;
111 ParentType parent_ = std::nullopt;
112 TagType tag_ = Generator::next();
125 explicit TagDecorator(ParentType parent = std::nullopt) : parent_{parent}
139 if (parent_.has_value())
140 (*parent_).get().decorate(os);
160 decorate([[maybe_unused]] std::ostream& os)
const override
170 using ParentType = std::optional<std::reference_wrapper<BaseTagDecorator const>>;
182 ParentType parent_ = std::nullopt;
185 getLogTagType(std::string_view style)
187 if (boost::iequals(style,
"int") || boost::iequals(style,
"uint"))
188 return TagDecoratorFactory::Type::UINT;
190 if (boost::iequals(style,
"null") || boost::iequals(style,
"none"))
191 return TagDecoratorFactory::Type::NONE;
193 if (boost::iequals(style,
"uuid"))
194 return TagDecoratorFactory::Type::UUID;
196 ASSERT(
false,
"log_tag_style does not have valid value");
209 : type_{getLogTagType(config.get<std::string>(
"log_tag_style"))}
224 std::unique_ptr<BaseTagDecorator>
234 with(ParentType parent)
const noexcept;
241 using DecoratorType = std::unique_ptr<BaseTagDecorator>;
242 DecoratorType tagDecorator_;
269 return *tagDecorator_;
Represents any tag decorator.
Definition Taggable.hpp:74
virtual void decorate(std::ostream &os) const =0
Decorates a std::ostream.
friend std::ostream & operator<<(std::ostream &os, BaseTagDecorator const &decorator)
Support for decorating streams (boost log, cout, etc.).
Definition Taggable.hpp:94
A factory for TagDecorator instantiation.
Definition Taggable.hpp:169
std::unique_ptr< BaseTagDecorator > make() const
Instantiates the TagDecorator specified by type_ with parent bound from parent_.
Definition Taggable.cpp:52
TagDecoratorFactory(util::config::ClioConfigDefinition const &config)
Instantiates a tag decorator factory from clio configuration.
Definition Taggable.hpp:208
TagDecoratorFactory with(ParentType parent) const noexcept
Creates a new tag decorator factory with a bound parent tag decorator.
Definition Taggable.cpp:66
void decorate(std::ostream &os) const override
Nop implementation for the decorator.
Definition Taggable.hpp:160
A decorator that decorates a string (log line) with a unique tag.
Definition Taggable.hpp:107
void decorate(std::ostream &os) const override
Implementation of the decoration. Chaining tags when parent is available.
Definition Taggable.hpp:135
TagDecorator(ParentType parent=std::nullopt)
Create a new tag decorator with an optional parent.
Definition Taggable.hpp:125
A base class that allows attaching a tag decorator to a subclass.
Definition Taggable.hpp:240
BaseTagDecorator const & tag() const
Getter for tag decorator.
Definition Taggable.hpp:267
Taggable(util::TagDecoratorFactory const &tagFactory)
New Taggable from a specified factory.
Definition Taggable.hpp:250
All the config data will be stored and extracted from this class.
Definition ConfigDefinition.hpp:54
This namespace contains various utilities.
Definition AccountUtils.hpp:30
A null tag generator - does nothing.
Definition Taggable.hpp:47
This strategy uses an atomic_uint64_t to remain lock free.
Definition Taggable.hpp:52
This strategy uses boost::uuids::uuid with a static random generator and a mutex.
Definition Taggable.hpp:62