Config
This module provides helpers to handle MetlogClient configuration details.
-
metlog.config._convert(value)[source]
Converts a config value. Numeric integer strings are converted to
integer values. ‘True-ish’ string values are converted to boolean True,
‘False-ish’ to boolean False. Any alphanumeric (plus underscore) value
enclosed within ${dollar_sign_curly_braces} is assumed to represent an
environment variable, and will be converted to the corresponding value
provided by os.environ.
-
metlog.config.client_from_dict_config(config, client=None, clear_global=False)[source]
Configure a metlog client, fully configured w/ sender and plugins.
Parameters: |
- config – Configuration dictionary.
- client – MetlogClient instance to configure. If None, one will be
created.
- clear_global – If True, delete any existing global config on the
CLIENT_HOLDER before applying new config.
|
The configuration dict supports the following values:
- logger
- Metlog client default logger value.
- severity
- Metlog client default severity value.
- disabled_timers
- Sequence of string tokens identifying timers that are to be deactivated.
- filters
- Sequence of 2-tuples (filter_provider, config). Each filter_provider
is a dotted name referring to a function which, when called and passed
the associated config dict as kwargs, will return a usable MetlogClient
filter function.
- plugins
- Nested dictionary containing plugin configuration. Keys are the plugin
names (i.e. the name the method will be given when attached to the
client). Values are 2-tuples (plugin_provider, config). Each
plugin_provider is a dotted name referring to a function which, when
called and passed the associated config, will return the usable plugin
method.
- sender
- Nested dictionary containing sender configuration.
- global
- Dictionary to be applied to CLIENT_HOLDER’s global_config storage.
New config will overwrite any conflicting values, but will not delete
other config entries. To delete, calling code should call the function
with clear_global set to True.
All of the configuration values are optional, but failure to include a
sender may result in a non-functional Metlog client. Any unrecognized keys
will be ignored.
Note that any top level config values starting with sender_ will be added
to the sender config dictionary, overwriting any values that may already
be set.
The sender configuration supports the following values:
- class (required)
- Dotted name identifying the sender class to instantiate.
- args
- Sequence of non-keyword args to pass to sender constructor.
- <kwargs>
- All remaining key-value pairs in the sender config dict will be passed as
keyword arguments to the sender constructor.
-
metlog.config.client_from_stream_config(stream, section, client=None, clear_global=False)[source]
Extract configuration data in INI format from a stream object (e.g. a file
object) and use it to generate a Metlog client. Config values will be sent
through the _convert function for possible type conversion.
Parameters: |
- stream – Stream object containing config information.
- section – INI file section containing the configuration we care
about.
- client – MetlogClient instance to configure. If None, one will be
created.
|
Note that all sender config options should be prefaced by “sender_”, e.g.
“sender_class” should specify the dotted name of the sender class to use.
Similarly all extension method settings should be prefaced by
“extensions_”. Any values prefaced by “global_” will be added to the global
config dictionary.
-
metlog.config.client_from_text_config(text, section, client=None, clear_global=False)[source]
Extract configuration data in INI format from provided text and use it to
configure a Metlog client. Text is converted to a stream and passed on to
client_from_stream_config.
Parameters: |
- text – INI text containing config information.
- section – INI file section containing the configuration we care
about.
- client – MetlogClient instance to configure. If None, one will be
created.
|
-
metlog.config.dict_from_stream_config(stream, section)[source]
Parses configuration from a stream and converts it to a dictionary suitable
for passing to client_from_dict_config.
Parameters: |
- stream – Stream object containing config information.
- section – INI file section containing the configuration we care
about.
|
-
metlog.config.nest_prefixes(config_dict, prefixes=None, separator='_')[source]
Iterates through the config_dict keys, looking for any starting w/ one of
a specific set of prefixes, moving those into a single nested dictionary
keyed by the prefix value.
Parameters: |
- config_dict – Dictionary to mutate. Will also be returned.
- prefixes – Sequence of prefixes to look for in config_dict keys.
- separator – String which separates prefix values from the rest of the
key.
|