Skip to content

octoprint.logging#

get_divider_line(c, message = None, length = 78, indent = 3) #

Generate a divider line for logging, optionally with included message.

Examples:

>>> get_divider_line("-")
'------------------------------------------------------------------------------'
>>> get_divider_line("=", length=10)
'=========='
>>> get_divider_line("-", message="Hi", length=10)
'--- Hi ---'
>>> get_divider_line("-", message="A slightly longer text")
'--- A slightly longer text ---------------------------------------------------'
>>> get_divider_line("-", message="A slightly longer text", indent=5)
'----- A slightly longer text -------------------------------------------------'
>>> get_divider_line("-", message="Hello World!", length=10)
'--- Hello World!'
>>> get_divider_line(None)
Traceback (most recent call last):
  ...
AssertionError: c is not text
>>> get_divider_line("´`")
Traceback (most recent call last):
  ...
AssertionError: c is not a single character
>>> get_divider_line("-", message=3)
Traceback (most recent call last):
  ...
AssertionError: message is not text
>>> get_divider_line("-", length="hello")
Traceback (most recent call last):
  ...
AssertionError: length is not an int
>>> get_divider_line("-", indent="hi")
Traceback (most recent call last):
  ...
AssertionError: indent is not an int

Parameters:

  • c (str) –

    character to use for the line

  • message (str) –

    message to print in the line

  • length (int) –

    length of the line

  • indent (int) –

    indentation of message in line

Returns:

  • str

    formatted divider line

get_handler(name, logger = None) #

Retrieves the handler named name.

If optional logger is provided, search will be limited to that logger, otherwise the root logger will be searched.

Parameters:

  • name (str) –

    the name of the handler to look for

  • logger (logging.loggers.Logger) –

    (optional) the logger to search in, root logger if not provided

Returns:

  • logging.handlers.Handler | None

    the handler if it could be found, None otherwise

log_to_handler(logger, handler, level, msg, exc_info = None, extra = None, *args) #

Logs to the provided handler only.

Parameters:

  • logger (logging.Logger) –

    logger to log to

  • handler (logging.Handler) –

    handler to restrict logging to

  • level (int) –

    level to log at

  • msg (str) –

    message to log

  • exc_info

    optional exception info

  • extra

    optional extra data

  • *args

    log args

prefix_multilines(text: str, prefix: str = ': ') -> str #

Prefixes all lines of the given text with the given prefix.

Parameters:

  • text (str) –

    text to prefix

  • prefix (str) –

    prefix to use

Returns:

  • str

    prefixed text