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:

Name Type Description Default
c

character to use for the line

required
message

message to print in the line

None
length

length of the line

78
indent

indentation of message in line

3

Returns:

Type Description

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 Type Description Default
name

the name of the handler to look for

required
logger

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

None

Returns:

Type Description

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:

Name Type Description Default
logger

logger to log to

required
handler

handler to restrict logging to

required
level

level to log at

required
msg

message to log

required
exc_info

optional exception info

None
extra

optional extra data

None
*args

log args

()
Back to top