yagwr.logger: Logging helpers

class yagwr.logger.NamedLogger(logger, extra)

Bases: logging.LoggerAdapter

A logging adapater that uses the passed name in square brackets as a prefix.

The extra arguments are name, a string. If name is not present or if it’s None, no prefix is used.

Initialize the adapter with a logger and a dict-like object which provides contextual information. This constructor signature allows easy stacking of LoggerAdapters, if so desired.

You can effectively pass keyword arguments as shown in the following example:

adapter = LoggerAdapter(someLogger, dict(p1=v1, p2=”v2”))

process(msg, kwargs)

Process the logging message and keyword arguments passed in to a logging call to insert contextual information. You can either manipulate the message itself, the keyword args or both. Return the message and kwargs modified (or not) to suit your needs.

Normally, you’ll only need to override this one method in a LoggerAdapter subclass for your specific needs.

exception yagwr.logger.LoggerConfigError

Bases: Exception

Exception raised when a configuration error is detected

yagwr.logger.setup_logger(log_file, log_level, quiet, log_rotate=None, log_rotate_arg=None)

Setups the logging based on log_file, log_level, quiet.

Parameters
  • log_file (str) – the log file, "stderr" or "stdout"

  • log_level (int) – a log level

  • quiet (bool) – If set to True, then logging is suppressed

  • log_rotate (str) – the type of rotation, "time" or "size"

  • log_rotate_arg (str) – rotation arguments

Raises

LoggerConfigError – when the settings are incorrect