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.

  • 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: logging.NullHandler

A logging handler that counts the number of times a specific type of message is logged per loglevel.

  • type_attribute (str) – The name of the attribute carrying the type.
  • default_type (str) – The type of message if none is provided.

Handle a log record by counting it.

number_of_counts_by(level=None, type=None)[source]

Return the number of logging calls counted, filtered by level and type.

  • level – Only count log events of this level.
  • type – Only count log events of this type.

The number of events counted.

Return type:


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: logging.LoggerAdapter

Helper class that is actually capable of chaining multiple LoggerAdapters.

addHandler(*args, **kwargs)[source]
log(level, msg, *args, **kwargs)[source]
Logger.manager = <logging.Manager object>
process(msg, kwargs)[source]
class vermouth.log_helpers.StyleAdapter(logger, extra=None)[source]

Bases: vermouth.log_helpers.PassingLoggerAdapter

Logging adapter that encapsulate messages in Message, allowing {} style formatting.

log(level, msg, *args, **kwargs)[source]
class vermouth.log_helpers.TypeAdapter(logger, extra=None, default_type='general')[source]

Bases: vermouth.log_helpers.PassingLoggerAdapter

Logging adapter that takes the type keyword argument passed to logging calls and passes adds it to the extra attribute.

process(msg, kwargs)[source]

Convenience method that wraps a TypeAdapter around logging.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 is None if all warnings of that type should be ignored, and the warning type is None 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.