22#include "util/Assert.hpp"
23#include "util/config/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;
108 std::ostringstream oss;
110 return std::move(oss).str();
119template <
typename Generator>
121 using ParentType = std::optional<std::reference_wrapper<BaseTagDecorator const>>;
122 using TagType =
typename Generator::TagType;
124 ParentType parent_ = std::nullopt;
125 TagType tag_ = Generator::next();
138 explicit TagDecorator(ParentType parent = std::nullopt) : parent_{parent}
152 if (parent_.has_value())
153 (*parent_).get().decorate(os);
173 decorate([[maybe_unused]] std::ostream& os)
const override
183 using ParentType = std::optional<std::reference_wrapper<BaseTagDecorator const>>;
195 ParentType parent_ = std::nullopt;
198 getLogTagType(std::string_view style)
200 if (boost::iequals(style,
"int") || boost::iequals(style,
"uint"))
201 return TagDecoratorFactory::Type::UINT;
203 if (boost::iequals(style,
"null") || boost::iequals(style,
"none"))
204 return TagDecoratorFactory::Type::NONE;
206 if (boost::iequals(style,
"uuid"))
207 return TagDecoratorFactory::Type::UUID;
209 ASSERT(
false,
"log_tag_style does not have valid value");
222 : type_{getLogTagType(config.get<std::string>(
"log_tag_style"))}
237 std::unique_ptr<BaseTagDecorator>
247 with(ParentType parent)
const noexcept;
254 using DecoratorType = std::unique_ptr<BaseTagDecorator>;
255 DecoratorType tagDecorator_;
282 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
std::string toString() const
Gets the string representation of the tag.
Definition Taggable.hpp:106
A factory for TagDecorator instantiation.
Definition Taggable.hpp:182
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:221
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:173
A decorator that decorates a string (log line) with a unique tag.
Definition Taggable.hpp:120
void decorate(std::ostream &os) const override
Implementation of the decoration. Chaining tags when parent is available.
Definition Taggable.hpp:148
TagDecorator(ParentType parent=std::nullopt)
Create a new tag decorator with an optional parent.
Definition Taggable.hpp:138
A base class that allows attaching a tag decorator to a subclass.
Definition Taggable.hpp:253
BaseTagDecorator const & tag() const
Getter for tag decorator.
Definition Taggable.hpp:280
Taggable(util::TagDecoratorFactory const &tagFactory)
New Taggable from a specified factory.
Definition Taggable.hpp:263
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