fora.logger
Provides logging utilities.
Attributes
attr logger.state
logger.state
The global logger state.
class logger.State
logger.State
Global state for logging.
Attributes
attr indentation_level
indentation_level
The current global indentation level.
class logger.IndentationContext
logger.IndentationContext
A context manager to modify the indentation level.
Functions
def logger.use_color()
logger.use_color()
Returns true if color should be used.
def logger.col()
logger.col()
Returns the given argument only if color is enabled.
def logger.ellipsis()
logger.ellipsis()
Shrinks the given string to width (including an ellipsis character).
Parameters
s: The string.
width: The maximum width.
Returns
str: A modified string with at most
width
characters.
def logger.indent()
logger.indent()
Retruns a context manager that increases the indentation level.
def logger.indent_prefix()
logger.indent_prefix()
Returns the indentation prefix for the current indentation level.
def logger.debug()
logger.debug()
Prints the given message only in debug mode.
def logger.debug_args()
logger.debug_args()
Prints all given arguments when in debug mode.
def logger.print_indented()
logger.print_indented()
Same as print(), but prefixes the message with the indentation prefix.
def logger.connection_init()
logger.connection_init()
Prints connection initialization information.
def logger.connection_failed()
logger.connection_failed()
Signals that an error has occurred while establishing the connection.
def logger.connection_established()
logger.connection_established()
Signals that the connection has been successfully established.
def logger.run_script()
logger.run_script()
Prints the script file and name that is being executed next.
def logger.print_operation_title()
logger.print_operation_title()
Prints the operation title and description.
def logger.print_operation_early()
logger.print_operation_early()
Prints the operation title and description before the final status is known.
def logger.decode_escape()
logger.decode_escape()
Tries to decode the given data with the given encoding, but replaces all non-decodeable and non-printable characters with backslash escape sequences.
Example:
Parameters
content: The content that should be decoded and escaped.
encoding: The encoding that should be tried. To preserve utf-8 symbols, use 'utf-8', to replace any non-ascii character with an escape sequence use 'ascii'.
Returns
str: The decoded and escaped string.
def logger.diff()
logger.diff()
Creates a diff between the old and new content of the given filename, that can be printed to the console. This function returns the diff output as an array of lines. The lines in the output array are not terminated by newlines.
If color is True, the diff is colored using ANSI escape sequences.
If you want to provide an alternative diffing function, beware that the input can theoretically contain any bytes and therefore should be decoded as utf-8 if possible, but non-decodeable or non-printable charaters should be replaced with human readable variants such as \x00
, ^@
or similar represenations.
Your diffing function should still be able to work on the raw bytes representation, after you aquire the diff and before you apply colors, your output should be made printable with a function such as logger.decode_escape()
:
Parameters
filename: The filename of the file that is being diffed.
old: The old content, or None if the file didn't exist before.
new: The new content, or None if the file was deleted.
color: Whether the output should be colored (with ANSI color sequences).
Returns
list[str]: The lines of the diff output. The individual lines will not have a terminating newline.
def logger.print_operation()
logger.print_operation()
Prints the operation summary after it has finished execution.
Last updated