3#include "util/Assert.hpp"
4#include "util/config/ConfigDefinition.hpp"
6#include <boost/algorithm/string/predicate.hpp>
7#include <boost/json.hpp>
8#include <boost/json/conversion.hpp>
9#include <boost/json/value.hpp>
10#include <boost/uuid/uuid.hpp>
11#include <boost/uuid/uuid_io.hpp>
34 using TagType = std::atomic_uint64_t;
44 using TagType = boost::uuids::uuid;
89 std::ostringstream oss;
91 return std::move(oss).str();
100template <
typename Generator>
102 using ParentType = std::optional<std::reference_wrapper<BaseTagDecorator const>>;
103 using TagType =
typename Generator::TagType;
105 ParentType parent_ = std::nullopt;
106 TagType tag_ = Generator::next();
120 explicit TagDecorator(ParentType parent = std::nullopt) : parent_{parent}
134 if (parent_.has_value())
135 (*parent_).get().decorate(os);
156 decorate([[maybe_unused]] std::ostream& os)
const override
166 using ParentType = std::optional<std::reference_wrapper<BaseTagDecorator const>>;
178 ParentType parent_ = std::nullopt;
181 getLogTagType(std::string_view style)
183 if (boost::iequals(style,
"int") || boost::iequals(style,
"uint"))
184 return TagDecoratorFactory::Type::UINT;
186 if (boost::iequals(style,
"null") || boost::iequals(style,
"none"))
187 return TagDecoratorFactory::Type::NONE;
189 if (boost::iequals(style,
"uuid"))
190 return TagDecoratorFactory::Type::UUID;
192 ASSERT(
false,
"log.tag_style does not have valid value");
205 : type_{getLogTagType(config.get<std::string>(
"log.tag_style"))}
220 std::unique_ptr<BaseTagDecorator>
230 with(ParentType parent)
const noexcept;
237 using DecoratorType = std::unique_ptr<BaseTagDecorator>;
238 DecoratorType tagDecorator_;
247 : tagDecorator_{tagFactory.make()}
266 return *tagDecorator_;
Represents any tag decorator.
Definition Taggable.hpp:55
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:75
std::string toString() const
Gets the string representation of the tag.
Definition Taggable.hpp:87
A factory for TagDecorator instantiation.
Definition Taggable.hpp:165
std::unique_ptr< BaseTagDecorator > make() const
Instantiates the TagDecorator specified by type_ with parent bound from parent_.
Definition Taggable.cpp:33
TagDecoratorFactory(util::config::ClioConfigDefinition const &config)
Instantiates a tag decorator factory from clio configuration.
Definition Taggable.hpp:204
TagDecoratorFactory with(ParentType parent) const noexcept
Creates a new tag decorator factory with a bound parent tag decorator.
Definition Taggable.cpp:47
void decorate(std::ostream &os) const override
Nop implementation for the decorator.
Definition Taggable.hpp:156
void decorate(std::ostream &os) const override
Implementation of the decoration. Chaining tags when parent is available.
Definition Taggable.hpp:130
TagDecorator(ParentType parent=std::nullopt)
Create a new tag decorator with an optional parent.
Definition Taggable.hpp:120
A base class that allows attaching a tag decorator to a subclass.
Definition Taggable.hpp:236
BaseTagDecorator const & tag() const
Getter for tag decorator.
Definition Taggable.hpp:264
Taggable(util::TagDecoratorFactory const &tagFactory)
New Taggable from a specified factory.
Definition Taggable.hpp:246
All the config data will be stored and extracted from this class.
Definition ConfigDefinition.hpp:31
This namespace contains various utilities.
Definition AccountUtils.hpp:11
A null tag generator - does nothing.
Definition Taggable.hpp:28
This strategy uses an atomic_uint64_t to remain lock free.
Definition Taggable.hpp:33
This strategy uses boost::uuids::uuid with a static random generator and a mutex.
Definition Taggable.hpp:43