API Reference¶
This page contains the full reference guide for using the logindent API.
- class logindent.IndentLogger¶
Utility class to implement structurally indented log messages.
Properties¶
- property IndentLogger.logger¶
The logging.Logger object that indented messages will be emitted to.
- property IndentLogger.indent_level¶
An integer indicating the number of indentation strings that will be prepended to logged messages.
- property IndentLogger.indent_string¶
The string used to represent a single level of indentation.
Dunders¶
- IndentLogger.__init__(self, logger, indent_level=0, indent_string=' ')¶
Creates a new
IndentLoggerIndentLogger(logger) IndentLogger(logger, indent_level) IndentLogger(logger, indent_level, indent_string)
Returns an IndentLogger for the indicated logger. The
loggermay be a logger name (string), a logging.Logger object, or another IndentLogger object.By default, the indent level will be set to 0. Use
indent_levelto specify a different indent level instead.The default indent string is 4 spaces. Use
indent_stringto use a different string instead. Note that this string is the string used to represent a single level of indenting.- Args:
logger (str | logging.Logger | IndentLogger) – Specifies the logging.Logger object that indented messages will be emitted to. May be a logger name (string),
logging.Loggerobject, or anotherIndentLoggerindent_level (int, optional) – The number of indent levels that should appear before logged messages. Defaults to 0.
indent_string (str, optional) – The string used to represent a single level of indenting. Defaults to 4 spaces (
" ")
- IndentLogger.__repr__(self)¶
Returns a string representation of an
IndentLoggerobject.- Returns:
str – The string representation of the
IndentLogger
Indenting¶
- IndentLogger.indent(self)¶
Increments an IndentLogger’s indent level by 1 within a context block.
Example:
logger.info("Some step") with logger.indent(): logger.info("Some sub-step")
INFO - Some step INFO - Some sub-step
- IndentLogger.indented(self)¶
Returns an
IndentLoggerat the next indent level.Example:
logger.info("Some task") task_logger = logger.indented() task_logger.info("Some step")
INFO - Some task INFO - Some step
Logging Messages¶
- IndentLogger.log(self, level, message)¶
Logs a message at the given logging level. Indentation will be prepended to the message before the message is emitted to logging streams.
Note
This method sets the logging level. It does not set the indent level, which is managed by the indent and indented methods.
- Args:
level (int) – The logging level that the message should be logged at.
message (str) – The message that should be logged
- IndentLogger.debug(self, message)¶
Logs a message at the DEBUG level.
- Args:
message (str) – The message that should be logged
- IndentLogger.info(self, message)¶
Logs a message at the INFO level.
- Args:
message (str) – The message that should be logged
- IndentLogger.warning(self, message)¶
Logs a message at the WARNING level.
- Args:
message (str) – The message that should be logged
- IndentLogger.error(self, message)¶
Logs a message at the ERROR level.
- Args:
message (str) – The message that should be logged
- IndentLogger.critical(self, message)¶
Logs a message at the CRITICAL level.
- Args:
message (str) – The message that should be logged