Flow 1.0.1
Flow project: Public API.
Public Types | Public Member Functions | Static Public Attributes | Related Functions | List of all members
flow::log::Verbosity_config Class 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.
 

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_seqcomponent_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...
 

Detailed Description

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.

Member Function Documentation

◆ apply_to_config()

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).

Parameters
target_configThe log::Config to reset.
Returns
true if and only if successfully applied. See also last_result_message().

◆ component_sev_pairs()

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:

  1. If empty, or the first pair's component name is not "", then act as-if there was an additional front-inserted pair ("", Config::S_MOST_VERBOSE_SEV_DEFAULT).
  2. For the first pair: 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.
  3. For each subsequent pair (name, v):
    • If the name is "": cfg.configure_default_verbosity(v, false);.
    • Otherwise: cfg.configure_component_verbosity_by_name(v, name);.
Returns
See above.

◆ last_result_message()

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.

Returns
See above.

◆ parse()

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:

  • No S_PAIR_SEPARATOR; just a Severity readable via its 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).
  • ":sev" (where the colon stands for S_PAIR_SEPARATOR): As-if simply "sev" (previous bullet point).
  • "ALL:sev" (ditto re. colon): ALL is S_ALL_COMPONENT_NAME_ALIAS: Same meaning as previous bullet point.
  • "name:sev" (ditto re. colon): 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.

Parameters
isInput stream.
Returns
true if and only if successfully deserialized. See also last_result_message().

Friends And Related Function Documentation

◆ operator!=()

bool operator!= ( const Verbosity_config val1,
const Verbosity_config val2 
)
related

Returns !(val1 == val2).

Parameters
val1Object to compare.
val2Object to compare.
Returns
See above.

◆ operator<<()

std::ostream & operator<< ( std::ostream &  os,
const Verbosity_config val 
)
related

Serializes a Verbosity_config to a standard output stream.

Parameters
osStream to which to serialize.
valValue to serialize.
Returns
os.

◆ operator==()

bool operator== ( const Verbosity_config val1,
const Verbosity_config val2 
)
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.

Parameters
val1Object to compare.
val2Object to compare.
Returns
true if definitely equal; false if possibly not equal.

◆ operator>>()

std::istream & operator>> ( std::istream &  is,
Verbosity_config val 
)
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.

Parameters
isStream from which to deserialize.
valValue to set.
Returns
is.

The documentation for this class was generated from the following files: