pypz.core.commons.loggers module

class pypz.core.commons.loggers.ContextLogger(logger: ContextLoggerInterface, *context_stack: str)

Bases: ContextLoggerInterface

This class has the responsibility to provide a simple logging interface, which hides the complexity of maintaining the context information. The user can call the familiar methods without knowing, how the context information are handled by the protected methods.

By expecting a logger in the constructor we are allowing to reuse existing loggers from higher contexts i.e., a top-level instance can provide it’s logger to the nested instances along with the context information. The nested instance can further forward to it’s nested instances and so on. Each instance provides itself to the context stack so, if a logger method of the actual context will be called, then the logger itself will get the context information automatically.

Parameters:
  • logger – a logger implementation that will be used to route the messages to

  • context_stack – the information about the current and previous contexts

_abc_impl = <_abc._abc_data object>
_context_stack: list[str]

The context stack, which contains the actual and all parent contexts

_debug(event: str | None = None, context_stack: list[str] = None, *args: Any, **kw: Any) Any
_error(event: str | None = None, context_stack: list[str] = None, *args: Any, **kw: Any) Any
_info(event: str | None = None, context_stack: list[str] = None, *args: Any, **kw: Any) Any
_logger: ContextLoggerInterface

The provided logger to use on this context

_warning(event: str | None = None, context_stack: list[str] = None, *args: Any, **kw: Any) Any
debug(event: str | None = None, *args: Any, **kw: Any) Any
error(event: str | None = None, *args: Any, **kw: Any) Any
get_context_stack() list[str]
info(event: str | None = None, *args: Any, **kw: Any) Any
set_log_level(log_level: str | int) None
warning(event: str | None = None, *args: Any, **kw: Any) Any
class pypz.core.commons.loggers.ContextLoggerInterface

Bases: ABC

This interface provides the necessary methods to be able to implement the context logging functionality. Context logging means that there is exactly one logger, which will be (re)used in the given context.

_abc_impl = <_abc._abc_data object>
abstract _debug(event: str | None = None, context_stack: list[str] = None, *args: Any, **kw: Any) Any
abstract _error(event: str | None = None, context_stack: list[str] = None, *args: Any, **kw: Any) Any
abstract _info(event: str | None = None, context_stack: list[str] = None, *args: Any, **kw: Any) Any
abstract _warning(event: str | None = None, context_stack: list[str] = None, *args: Any, **kw: Any) Any
set_log_level(log_level: Any) None
class pypz.core.commons.loggers.DefaultContextLogger(name: str = None)

Bases: ContextLoggerInterface

The default implementation of the ContextLoggerInterface, which will send log messages to the standard out.

Parameters:

name – name of the instance, if not provided, it will be attempted to deduce from the variable’s name

class ColoredFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)

Bases: Formatter

This class overrides the default logging Formatter class to be able to colorize log records. It applies to the entire record not just to the log message.

BLUE = '\x1b[34m'
CYAN = '\x1b[36m'
GREEN = '\x1b[32m'
LIGHT_GRAY = '\x1b[37m'
PURPLE = '\x1b[35m'
RED = '\x1b[31m'
RESET = '\x1b[0m'
WHITE = '\x1b[37m'
YELLOW = '\x1b[33m'
format(record)

Format the specified record as text.

The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.

_abc_impl = <_abc._abc_data object>
_debug(event: str | None = None, context_stack: list[str] = None, *args: Any, **kw: Any) Any
_error(event: str | None = None, context_stack: list[str] = None, *args: Any, **kw: Any) Any
_info(event: str | None = None, context_stack: list[str] = None, *args: Any, **kw: Any) Any
_warning(event: str | None = None, context_stack: list[str] = None, *args: Any, **kw: Any) Any
set_log_level(log_level: str | int) None