Flow 1.0.2
Flow project: Public API.
|
Optional-use structure encapsulating a full set of verbosity config, such that one can parse it from a config source (like an options file) in concise form and apply it to a log::Config object. More...
#include <verbosity_config.hpp>
Public Types | |
using | Component_sev_pair_seq = std::vector< std::pair< std::string, Sev > > |
Short-hand for the configuration capable of being encapsulated by Verbosity_config. | |
Public Member Functions | |
Verbosity_config () | |
Constructor a Verbosity_config that resets all severity config and sets the default/catch-all to Config::S_MOST_VERBOSE_SEV_DEFAULT. | |
bool | parse (std::istream &is) |
Deserializes *this from a standard input stream. More... | |
bool | apply_to_config (Config *target_config) |
Applies *this to to the given log::Config. More... | |
const std::string & | last_result_message () const |
To be used after parse() or operator<< or apply_to_config(), returns "" on success or a message describing the problem on failure. More... | |
const Component_sev_pair_seq & | component_sev_pairs () const |
Read-only access to encapsulated config; specifies the verbosity-setting calls to make on a Config in order, given as component-name-to-severity pairs, with an empty component name specifying the default severity used when no component name is given. More... | |
Static Public Attributes | |
static const std::string | S_ALL_COMPONENT_NAME_ALIAS |
String that Verbosity_config::parse() treats as the default/catch-all verbosity's "component" specifier. | |
static const char | S_TOKEN_SEPARATOR |
Separates component/severity pairs in a Verbosity_config specifier string. | |
static const char | S_PAIR_SEPARATOR |
Separates component and severity within each pair in a Verbosity_config specifier string. | |
Related Functions | |
(Note that these are not member functions.) | |
std::istream & | operator>> (std::istream &is, Verbosity_config &val) |
Deserializes a Verbosity_config from a standard input stream by invoking val.parse(is) . More... | |
std::ostream & | operator<< (std::ostream &os, const Verbosity_config &val) |
Serializes a Verbosity_config to a standard output stream. More... | |
bool | operator== (const Verbosity_config &val1, const Verbosity_config &val2) |
Checks for exact equality of two Verbosity_config objects. More... | |
bool | operator!= (const Verbosity_config &val1, const Verbosity_config &val2) |
Returns !(val1 == val2) . More... | |
Optional-use structure encapsulating a full set of verbosity config, such that one can parse it from a config source (like an options file) in concise form and apply it to a log::Config object.
Put simply, one can read a string like "ALL:2;COOL_COMPONENT:4;ANOTHER_COMPONENT:TRACE"
from an istream
via >>
; then this->apply_to_config(&cfg)
, where cfg
is a log::Config
; resulting in the necessary Config::configure_default_verbosity()
and Config::configure_component_verbosity_by_name()
calls that will set the default verbosity to INFO and those specific components' verbosities to DATA and TRACE respectively in order.
bool flow::log::Verbosity_config::apply_to_config | ( | Config * | target_config | ) |
Applies *this
to to the given log::Config.
Typically one would parse into *this
first.
Returns true
if this succeeded; else false
. last_result_message() can then be invoked to get further details suitable for display to the user in the case of false
. Typically this would only occur, as of this writing, on an unknown component name according to what has been registered on *target_config
.
If true
returned, the Config verbosity config is completely overwritten; otherwise it is reset and completely overwritten but may represent only a partial application (valid but typically not advisable to use).
target_config | The log::Config to reset. |
true
if and only if successfully applied. See also last_result_message(). const Verbosity_config::Component_sev_pair_seq & flow::log::Verbosity_config::component_sev_pairs | ( | ) | const |
Read-only access to encapsulated config; specifies the verbosity-setting calls to make on a Config in order, given as component-name-to-severity pairs, with an empty component name specifying the default severity used when no component name is given.
The assumed semantics as applied to a given log::Config cfg
are as follows:
("", Config::S_MOST_VERBOSE_SEV_DEFAULT)
.cfg.configure_default_verbosity(v, true);
, where v
is the log::Sev in that slot. In other words the config is reset, and the catch-all default verbosity is initialized to that severity.(name, v)
:name
is "": cfg.configure_default_verbosity(v, false);
.cfg.configure_component_verbosity_by_name(v, name);
.const std::string & flow::log::Verbosity_config::last_result_message | ( | ) | const |
To be used after parse() or operator<<
or apply_to_config(), returns "" on success or a message describing the problem on failure.
bool flow::log::Verbosity_config::parse | ( | std::istream & | is | ) |
Deserializes *this
from a standard input stream.
Reads a single space-delimited token from the given stream. Separates that into a sequence of S_TOKEN_SEPARATOR-delimited pairs, each representing an element of what will be returnable via component_sev_pairs(), in order. Each pair is to be in one of the following forms:
istream<<
operator (as of this writing, a number "1", "2", ... or a string "WARNING", "INFO", etc.). Then this is taken to be the severity, and the component name for component_sev_pairs() is taken to be as-if "" (the default).ALL
is S_ALL_COMPONENT_NAME_ALIAS: Same meaning as previous bullet point.name
is the component name; sev
is the Severity readable via its istream<<
operator.Returns true
if the token was legal; else false
. last_result_message() can then be invoked to get further details suitable for display to the user in the case of false
.
If true
returned, the existing payload is completely overwritten. Otherwise it is untouched.
is | Input stream. |
true
if and only if successfully deserialized. See also last_result_message().
|
related |
Returns !(val1 == val2)
.
val1 | Object to compare. |
val2 | Object to compare. |
|
related |
Serializes a Verbosity_config to a standard output stream.
os | Stream to which to serialize. |
val | Value to serialize. |
os
.
|
related |
Checks for exact equality of two Verbosity_config objects.
(Note that this is not maximally clever, in that if (val1 == val2
), then they definitely produce the same Config all else being equal; but if the reverse is true, then it is possible they differently expressed values producing the same actual result. E.g., something like ALL:INFO
differs from ALL:WARN;ALL:INFO
– yet they have the same effect. However component names are normalized internally when parsing, so that won't produce false inequality.)
Only Verbosity_config::component_sev_pairs() is significant in this comparison; last_result_message() is not.
val1 | Object to compare. |
val2 | Object to compare. |
true
if definitely equal; false
if possibly not equal.
|
related |
Deserializes a Verbosity_config from a standard input stream by invoking val.parse(is)
.
val.last_result_message()
can be used to glean the success or failure of this operation.
is | Stream from which to deserialize. |
val | Value to set. |
is
.