Skip to content

pillar.logging 🔗

LoggingMixin 🔗

Bases: LoggingMixinBase

Adds shortcut logging methods to a class

Expects that a logging.Logger exists at self.logger

critical 🔗

critical(msg: str, *args, **kwargs) -> None

Log a CRITICAL message

Something is on fire. We somehow caught it but we probably need to exit now. If we keep going more things may catch on fire.

In a larger system, someone is probably going to get paged over this. An end user is definitely going to get an error message, probably not even a useful one, just a HTTP 500.

debug 🔗

debug(msg: str, *args, **kwargs) -> None

Log a DEBUG message

Basic debug messages

error 🔗

error(msg: str, *args, **kwargs) -> None

Log an ERROR message

Something bad has happened but we caught it. We might be able to continue, but other things might start breaking. We can probably still safely exit.

In a larger system, this will likely cause a gentle alert to be placed somewhere. An end user might receive a useful error message (like a HTTP 4xx 5xx).

get_logger classmethod 🔗

get_logger(prefix: str = '') -> logging.Logger

Get a logging.Logger for this class

Parameters:

Name Type Description Default
prefix str

optional prefix for the logger name

''

info 🔗

info(msg: str, *args, **kwargs) -> None

Log an INFO message

Print something to the screen/logfile so we know what is happening

vdebug 🔗

vdebug(msg: str, *args, **kwargs) -> None

Log a Verbose Debug (VDEBUG) message.

More than debug, less than everything.

vvdebug 🔗

vvdebug(msg: str, *args, **kwargs) -> None

Log a Very Verbose Debug (VVDEBUG) message.

When you're tired of finding the bug and want to log everything.

warning 🔗

warning(msg: str, *args, **kwargs) -> None

Log a WARNING message

Something is wrong but we likely can recover or skip it without issue.

In a larger system this will likely just go to centralised logging.

LoggingMixinBase 🔗

Base class for logging mixins

get_logger classmethod 🔗

get_logger(prefix: str = '') -> logging.Logger

Get a logging.Logger for this class

Parameters:

Name Type Description Default
prefix str

optional prefix for the logger name

''

NotFilter 🔗

NotFilter(name: str)

Bases: Filter

Ignore the given logger (and all subloggers).

Is the opposite of logging.Filter.

References
  • https://docs.python.org/3/library/logging.html#filter-objects

filter 🔗

filter(record) -> bool

As per logging.Filter.filter

UnderscoreLoggingMixin 🔗

Bases: LoggingMixinBase

Add shortcut logging methods to a class with underscore (_) prefix

Expects that a logging.Logger exists at self._logger.

get_logger classmethod 🔗

get_logger(prefix: str = '') -> logging.Logger

Get a logging.Logger for this class

Parameters:

Name Type Description Default
prefix str

optional prefix for the logger name

''

get_log_level 🔗

get_log_level(verbosity: int, default_level: int) -> int

Get the log level based on the default log level.

This function essentially adds a "verbosity level" per "major log level" lower than the default.

For example, if default_level == DEBUG, then verbosity == 1 will return VDEBUG and verbosity >= 2 will return VVDBEUG. For any defaul_level > INFO will always use 4 levels of verbosity (INFO, DEBUG, VDEBUG, VVDEBUG).

get_logger_name_for_class 🔗

get_logger_name_for_class(
    cls: Type[object], prefix: str = ""
) -> str

Get a logger name based on the qualified name of a class.

Parameters:

Name Type Description Default
cls Type[object]

object to inspect

required
prefix str

optional prefix for the logger name.

''

get_logger_name_for_instance 🔗

get_logger_name_for_instance(
    instance: object, prefix: str = ""
) -> str

Get a logger name based on the qualified name of this instance's class.

Parameters:

Name Type Description Default
instance object

object to inspect

required
prefix str

optional prefix for the logger name.

''

logging_file_handler_errors_kwargs 🔗

logging_file_handler_errors_kwargs(
    errors: str,
) -> Dict[str, str]

Generate FileHandler keyword argument if it is supported by this python version.

If it is not supported contains an empty dictionary.

To use it unpack it like so FileHandler(**logging_file_handler_errors_kwargs())