22#include <boost/unordered_map.hpp>
419 template<
typename Component_payload>
421 size_t enum_sparse_length);
505 template<
typename Component_payload>
506 void init_component_names(
const boost::unordered_multimap<Component_payload, std::string>& component_names,
507 bool output_components_numerically =
false,
561 template<
typename Component_payload>
609 template<
typename Component_payload>
800 static_assert(std::numeric_limits<component_union_idx_t>::is_integer
801 && (!std::numeric_limits<component_union_idx_t>::is_signed)
802 && (!std::numeric_limits<size_t>::is_signed)
804 "size_t must be able to act as equivalent to a component_union_idx_t key.");
928template<
typename Component_payload>
930 size_t enum_sparse_length)
932 using std::type_index;
934 assert(enum_sparse_length >= 1);
937 assert(component_union_idx_max >= enum_to_num_offset);
938 assert(component_union_idx_max >= enum_sparse_length);
942 const type_index idx(
typeid(Component_payload));
969template<
typename Component_payload>
971 (
const boost::unordered_multimap<Component_payload, std::string>& component_names,
972 bool output_components_numerically,
975 using std::type_index;
1002 for (
auto const & enum_val_and_name : component_names)
1004 const Component_payload enum_val = enum_val_and_name.first;
1006 auto name_sans_prefix_normalized = enum_val_and_name.second;
1007 assert(!name_sans_prefix_normalized.empty());
1010 string name_normalized;
1011 name_normalized.reserve(payload_type_prefix_normalized.size() + name_sans_prefix_normalized.size());
1012 name_normalized += payload_type_prefix_normalized;
1013 name_normalized += name_sans_prefix_normalized;
1033 if (!output_components_numerically)
1036 if (output_name_so_far.empty())
1038 assert(!name_normalized.empty());
1039 output_name_so_far = std::move(name_normalized);
1043 assert(!name_sans_prefix_normalized.empty());
1044 output_name_so_far +=
',';
1045 output_name_so_far += name_sans_prefix_normalized;
1057template<
typename Component_payload>
1060 using std::type_index;
1075template<
typename Component_payload>
1078 return size_t(Component_payload::S_END_SENTINEL);
A light-weight class, each object storing a component payload encoding an enum value from enum type o...
unsigned int enum_raw_t
The type Payload must be enum class Payload : enum_raw_t: an enum type encoded via this integer type.
Trivial wrapper of atomic<raw_sev_t> which adds a couple of things to make it possible to construct,...
Atomic_raw_sev(raw_sev_t init_val=raw_sev_t(-1))
Constructs the atomic to the given value, guaranteed to be load()ed as such in all subsequent accesse...
Class used to configure the filtering and logging behavior of Loggers; its use in your custom Loggers...
boost::unordered_map< std::type_index, Component_config > Component_payload_type_to_cfg_map
Short-hand for fast-lookup map from distinct Component_payload type to the config for that component ...
void init_component_to_union_idx_mapping(component_union_idx_t enum_to_num_offset, size_t enum_sparse_length)
Registers a generically-typed enum class that represents the full set of the calling module's possibl...
static size_t standard_component_payload_enum_sparse_length()
Returns highest numeric value in the given component-payload enum, plus 1, assuming that enum was cre...
void init_component_names(const boost::unordered_multimap< Component_payload, std::string > &component_names, bool output_components_numerically=false, util::String_view payload_type_prefix_or_empty=util::String_view())
Registers the string names of each member of the enum class Component_payload earlier registered via ...
bool m_use_human_friendly_time_stamps
Config setting: If true, time stamps will include a (deterministically formatted) date,...
Config(Sev most_verbose_sev_default=S_MOST_VERBOSE_SEV_DEFAULT)
Constructs a conceptually blank but functional set of Config.
static void normalize_component_name(std::string *name)
Normalizes given component name in place.
bool configure_component_verbosity_by_name(Sev most_verbose_sev, util::String_view component_name)
Like configure_component_verbosity(), but the component is to be specified by its registered string n...
Component_union_idx_to_name_map m_component_names_by_union_idx
Maps each flat union component index to its output component name as registered in init_component_nam...
std::vector< Atomic_raw_sev > Component_union_idx_to_sev_map
Short-hand for fast-lookup, thread-safe-for-RW mapping from flat-union-component-table index to max a...
Atomic_raw_sev m_verbosity_default
Most verbose (highest) log::Sev for which output_whether_should_log() will return true,...
static std::string normalized_component_name(util::String_view name)
Normalized version of given component name.
void operator=(const Config &)=delete
For now at least there's no reason for copy assignment.
bool output_component_to_ostream(std::ostream *os, const Component &component) const
An output of Config, this writes a string representation of the given component value to the given os...
boost::unordered_map< component_union_idx_t, std::string > Component_union_idx_to_name_map
Short-hand for map that is essentially the inverse of Component_name_to_union_idx_map.
Component_union_idx_to_sev_map m_verbosities_by_component
Maps from flat union component index to most verbose (highest) log::Sev for which output_whether_shou...
static Sev * this_thread_verbosity_override()
Returns pointer to this thread's mutable verbosity override, for querying or assignment alike.
static const Sev S_MOST_VERBOSE_SEV_DEFAULT
Recommended default/catch-all most-verbose-severity value if no specific config is given.
boost::unordered_map< std::string, component_union_idx_t > Component_name_to_union_idx_map
Short-hand for fast-lookup map from normalized component name to its flat-union-component-table index...
Component::enum_raw_t component_union_idx_t
Unsigned index into the flat union of component tables maintained by a Config, combining potentially ...
static util::Scoped_setter< Sev > this_thread_verbosity_override_auto(Sev most_verbose_sev_or_none)
Sets *(this_thread_verbosity_override()) = most_verbose_sev_or_none; and returns an object that shall...
Config(Config &&)=delete
For now at least there's no reason for move-construction.
void configure_default_verbosity(Sev most_verbose_sev_default, bool reset)
Sets the default verbosity to the given value, to be used by subsequent output_whether_should_log() c...
void operator=(Config &&)=delete
For now at least there's no reason for move assignment.
uint8_t raw_sev_t
How we store a log::Sev (a mere enum itself) in a certain data structure.
Component_name_to_union_idx_map m_component_union_idxs_by_name
Maps each distinct component name as registered in init_component_names() to its flat union component...
Config(const Config &src)
Copy-constructs *this to be equal to src config object.
bool configure_component_verbosity(Sev most_verbose_sev, Component_payload component_payload)
Sets the per-component verbosity for the given component to the given value, to be used by subsequent...
bool output_whether_should_log(Sev sev, const Component &component) const
A key output of Config, this computes the verbosity-filtering answer to Logger::should_log() based on...
Component_payload_type_to_cfg_map m_component_cfgs_by_payload_type
Fast-lookup map from distinct Component_payload type to the config for that component enum.
void store_severity_by_component(component_union_idx_t component_union_idx, raw_sev_t most_verbose_sev_or_none)
Helper that for the given flat-union-component-index saves the given per-component verbosity,...
component_union_idx_t component_to_union_idx(const Component &component) const
Given a component in the form user provides it at log call sites, returns its index in the flat compo...
A simple RAII-pattern class template that, at construction, sets the specified location in memory to ...
Flow module providing logging functionality.
Sev
Enumeration containing one of several message severity levels, ordered from highest to lowest.
bool key_exists(const Container &container, const typename Container::key_type &key)
Returns true if and only if the given key is present at least once in the given associative container...
Basic_string_view< char > String_view
Commonly used char-based Basic_string_view. See its doc header.
unsigned char uint8_t
Byte. Best way to represent a byte of binary data. This is 8 bits on all modern systems.
The set of config stored for each distinct (as determined by Component::payload_type(),...
component_union_idx_t m_enum_to_num_offset
See the enum_to_num_offset arg in init_component_to_union_idx_mapping() doc header.