Skip to content

indented_logger

A logger adapter that adds an indent to the beginning of each message.

Classes

IndentedLoggerAdapter

IndentedLoggerAdapter(logger: Logger, extra: Optional[dict] = None, depth: int = 2, indent_char: str = ' ', reset: bool = False)

Bases: LoggerAdapter

Logger adapter that adds an indent to the beginning of each message.

PARAMETER DESCRIPTION
logger

The logger to adapt.

TYPE: Logger

extra

Extra values to add to the logging context.

TYPE: Optional[dict] DEFAULT: None

depth

The number of indent_char to generate for each indent level.

TYPE: int DEFAULT: 2

indent_char

The character or string to use for indenting.

TYPE: str DEFAULT: ' '

reset

True if the indent level should be reset to zero.

TYPE: bool DEFAULT: False

Attributes

current_indent property
current_indent: int

The current indent level.

indent_str property
indent_str: str

The indent string.

Methods:

dedent
dedent(amount: int = 1) -> None

Decrease the indent level by amount.

indent
indent(amount: int = 1) -> None

Increase the indent level by amount.

process
process(msg: str, kwargs: Optional[MutableMapping[str, Any]]) -> Tuple[str, MutableMapping[str, Any]]

Process the message and add the indent.

PARAMETER DESCRIPTION
msg

The logging message.

TYPE: str

kwargs

Keyword arguments passed to the logger.

TYPE: Optional[MutableMapping[str, Any]]

RETURNS DESCRIPTION
Tuple[str, MutableMapping[str, Any]]

A tuple containing the message and keyword arguments.

reset
reset() -> None

Reset the indent level to zero.