vermouth.log_helpers module¶
Provide some helper classes to allow new style brace formatting for logging and processing the type keyword.
- class vermouth.log_helpers.BipolarFormatter(low_formatter, high_formatter, cutoff, logger=None)[source]¶
Bases:
object
A logging formatter that formats using either low_formatter or high_formatter depending on the logger’s effective loglevel.
- Parameters:
low_formatter (logging.Formatter) – The formatter used if cutoff <= logger.getEffectiveLevel().
high_formatter (logging.Formatter) – The formatter used if cutoff > logger.getEffectiveLevel().
cutoff (int) – The cutoff used to decide whether the low or high formatter is used.
logger (logging.Logger) – The logger whose effective loglevel is used. Defaults to
logging.getLogger()
.
- class vermouth.log_helpers.CountingHandler(*args, type_attribute='type', default_type='general', **kwargs)[source]¶
Bases:
NullHandler
A logging handler that counts the number of times a specific type of message is logged per loglevel.
- Parameters:
- class vermouth.log_helpers.Message(fmt, args, kwargs)[source]¶
Bases:
object
Class that defers string formatting until it’s
__str__
method is called.
- class vermouth.log_helpers.PassingLoggerAdapter(logger, extra=None)[source]¶
Bases:
LoggerAdapter
Helper class that is actually capable of chaining multiple LoggerAdapters.
- class vermouth.log_helpers.StyleAdapter(logger, extra=None)[source]¶
Bases:
PassingLoggerAdapter
Logging adapter that encapsulate messages in
Message
, allowing{}
style formatting.
- class vermouth.log_helpers.TypeAdapter(logger, extra=None, default_type='general')[source]¶
Bases:
PassingLoggerAdapter
Logging adapter that takes the type keyword argument passed to logging calls and passes adds it to the extra attribute.
- Parameters:
logger (logging.Logger or logging.LoggerAdapter) – As described in
logging.LoggerAdapter
.extra (dict) – As described in
logging.LoggerAdapter
.default_type (str) – The type of the messages if none is given.
- vermouth.log_helpers.get_logger(name)[source]¶
Convenience method that wraps a
TypeAdapter
aroundlogging.getLogger(name)
- Parameters:
name (str) – The name of the logger to get. Passed to
logging.getLogger()
. Should probably be__name__
.
- vermouth.log_helpers.ignore_warnings_and_count(counter, specifications, level=30)[source]¶
Count the warnings after deducting the ones to ignore.
Warnings to ignore are specified as tuple
(<warning-type>, <count>)
. The count isNone
if all warnings of that type should be ignored, and the warning type isNone
to indicate that the count is about all not specified types.In case the same type is specified more than once, only the higher count is used.