Flow 1.0.1
Flow project: Full implementation reference.
|
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. More... | |
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. More... | |
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. More... | |
static const char | S_TOKEN_SEPARATOR |
Separates component/severity pairs in a Verbosity_config specifier string. More... | |
static const char | S_PAIR_SEPARATOR |
Separates component and severity within each pair in a Verbosity_config specifier string. More... | |
Private Attributes | |
Component_sev_pair_seq | m_component_sev_pairs |
See component_sev_pairs(). More... | |
std::string | m_last_result_message |
See last_result_message(). More... | |
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.
Definition at line 41 of file verbosity_config.hpp.
using flow::log::Verbosity_config::Component_sev_pair_seq = std::vector<std::pair<std::string, Sev> > |
Short-hand for the configuration capable of being encapsulated by Verbosity_config.
Definition at line 47 of file verbosity_config.hpp.
flow::log::Verbosity_config::Verbosity_config | ( | ) |
Constructor a Verbosity_config that resets all severity config and sets the default/catch-all to Config::S_MOST_VERBOSE_SEV_DEFAULT.
Definition at line 34 of file verbosity_config.cpp.
References m_component_sev_pairs, and flow::log::Config::S_MOST_VERBOSE_SEV_DEFAULT.
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(). Definition at line 157 of file verbosity_config.cpp.
References m_component_sev_pairs, m_last_result_message, and flow::util::ostream_op_string().
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);
.Definition at line 199 of file verbosity_config.cpp.
References m_component_sev_pairs.
Referenced by operator<<(), and operator==().
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.
Definition at line 194 of file verbosity_config.cpp.
References m_last_result_message.
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(). Definition at line 44 of file verbosity_config.cpp.
References m_component_sev_pairs, m_last_result_message, flow::util::ostream_op_string(), S_ALL_COMPONENT_NAME_ALIAS, flow::log::Config::S_MOST_VERBOSE_SEV_DEFAULT, S_PAIR_SEPARATOR, and S_TOKEN_SEPARATOR.
Referenced by operator>>().
|
related |
Returns !(val1 == val2)
.
val1 | Object to compare. |
val2 | Object to compare. |
Definition at line 236 of file verbosity_config.cpp.
References flow::log::operator==().
|
related |
Serializes a Verbosity_config to a standard output stream.
os | Stream to which to serialize. |
val | Value to serialize. |
os
. Definition at line 210 of file verbosity_config.cpp.
References component_sev_pairs(), S_ALL_COMPONENT_NAME_ALIAS, S_PAIR_SEPARATOR, and S_TOKEN_SEPARATOR.
|
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. Definition at line 231 of file verbosity_config.cpp.
References component_sev_pairs().
|
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
. Definition at line 204 of file verbosity_config.cpp.
References parse().
|
private |
Definition at line 140 of file verbosity_config.hpp.
Referenced by apply_to_config(), component_sev_pairs(), parse(), and Verbosity_config().
|
private |
Definition at line 143 of file verbosity_config.hpp.
Referenced by apply_to_config(), last_result_message(), and parse().
|
static |
String that Verbosity_config::parse() treats as the default/catch-all verbosity's "component" specifier.
Definition at line 52 of file verbosity_config.hpp.
Referenced by operator<<(), and parse().
|
static |
Separates component and severity within each pair in a Verbosity_config specifier string.
Definition at line 58 of file verbosity_config.hpp.
Referenced by operator<<(), and parse().
|
static |
Separates component/severity pairs in a Verbosity_config specifier string.
Definition at line 55 of file verbosity_config.hpp.
Referenced by operator<<(), and parse().