knit_script.knit_script_interpreter.knitscript_logging.knitscript_logger module

A Module containing the Knit_Script_Logger class

class KnitScript_Logging_Level(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enumeration of logging levels for Knit_Script_Logger. Wraps the standard logging levels in the logging package.

info = 20
debug = 10
warning = 30
error = 40
critical = 50
print(message, logger)[source]

Prints the message to the appropriate level using the given logger. :param message: The message to print. :type message: str :param logger: The logger to print from. :type logger: Logger

classmethod __contains__(member)

Return True if member is a member of this enum raises TypeError if member is not an enum member

note: in 3.12 TypeError will no longer be raised, and True will also be returned if member is the value of a member in this enum

classmethod __getitem__(name)

Return the member matching name.

classmethod __iter__()

Return members in definition order.

classmethod __len__()

Return the number of members (no aliases)

class Knit_Script_Logger(log_to_console=True, log_to_file=False, logging_level=KnitScript_Logging_Level.info, log_name='KnitScript Console')[source]

Bases: object

A wrapping class for custom logging functionality used to control logging from knitscript separate from the python console.

__init__(log_to_console=True, log_to_file=False, logging_level=KnitScript_Logging_Level.info, log_name='KnitScript Console')[source]
Parameters:
  • log_to_console (bool, optional) – If True, the logger will output its contents to the python console. Defaults to True.

  • log_to_file (bool, optional) – If True, the logger will output its contents to a log file. Defaults to False.

  • logging_level (KnitScript_Logging_Level, optional) – The logging level of this logger. Defaults to logging information.

  • log_name (str, optional) – The name of the logger and the log file produced. Defaults to “KnitScript”.

property name: str

Returns: str: The name of this logger.

property is_info: bool

Returns: bool: True if this logs info messages, False otherwise.

property is_debug: bool

Returns: bool: True if this logs debug messages, False otherwise.

property is_warning: bool

Returns: bool: True if this logs warning messages, False otherwise.

property is_error: bool

Returns: bool: True if this logs error messages, False otherwise.

property is_critical: bool

Returns: bool: True if this logs critical messages, False otherwise.

print(message)[source]

Prints the given message using this logger at the set level. If this is the first message printed by the logger, it will add a start line to the output. :param message: The message to print. :type message: str

class KnitScript_Warning_Log(log_to_console=True, log_to_file=False, log_name='KnitScript Warnings')[source]

Bases: Knit_Script_Logger

Used for logging warning messages from Knit Script.

__init__(log_to_console=True, log_to_file=False, log_name='KnitScript Warnings')[source]
Parameters:
  • log_to_console (bool, optional) – If True, the logger will output its contents to the python console. Defaults to True.

  • log_to_file (bool, optional) – If True, the logger will output its contents to a log file. Defaults to False.

  • logging_level (KnitScript_Logging_Level, optional) – The logging level of this logger. Defaults to logging information.

  • log_name (str, optional) – The name of the logger and the log file produced. Defaults to “KnitScript”.

warn(warning, source_element)[source]

Prints out the given warning message. :param warning: The warning message to print. :type warning: RuntimeWarning :param source_element: The KS element that is the source of the warning. :type source_element: Any

property is_critical: bool

Returns: bool: True if this logs critical messages, False otherwise.

property is_debug: bool

Returns: bool: True if this logs debug messages, False otherwise.

property is_error: bool

Returns: bool: True if this logs error messages, False otherwise.

property is_info: bool

Returns: bool: True if this logs info messages, False otherwise.

property is_warning: bool

Returns: bool: True if this logs warning messages, False otherwise.

property name: str

Returns: str: The name of this logger.

print(message)

Prints the given message using this logger at the set level. If this is the first message printed by the logger, it will add a start line to the output. :param message: The message to print. :type message: str

class KnitScript_Error_Log(log_to_console=True, log_to_file=False, log_name='KnitScript Errors')[source]

Bases: Knit_Script_Logger

Used for logging error messages from Knit Script.

__init__(log_to_console=True, log_to_file=False, log_name='KnitScript Errors')[source]
Parameters:
  • log_to_console (bool, optional) – If True, the logger will output its contents to the python console. Defaults to True.

  • log_to_file (bool, optional) – If True, the logger will output its contents to a log file. Defaults to False.

  • logging_level (KnitScript_Logging_Level, optional) – The logging level of this logger. Defaults to logging information.

  • log_name (str, optional) – The name of the logger and the log file produced. Defaults to “KnitScript”.

report_error(error, source_element)[source]

Prints out the given error message. :param error: The error to report. :type error: BaseException :param source_element: The KS element that is the source of the error. :type source_element: Any

property is_critical: bool

Returns: bool: True if this logs critical messages, False otherwise.

property is_debug: bool

Returns: bool: True if this logs debug messages, False otherwise.

property is_error: bool

Returns: bool: True if this logs error messages, False otherwise.

property is_info: bool

Returns: bool: True if this logs info messages, False otherwise.

property is_warning: bool

Returns: bool: True if this logs warning messages, False otherwise.

property name: str

Returns: str: The name of this logger.

print(message)

Prints the given message using this logger at the set level. If this is the first message printed by the logger, it will add a start line to the output. :param message: The message to print. :type message: str

class KnitScript_Debug_Log(log_to_console=True, log_to_file=False, log_name='KnitScript Debugger')[source]

Bases: Knit_Script_Logger

Used for logging debug messages from Knit Script.

__init__(log_to_console=True, log_to_file=False, log_name='KnitScript Debugger')[source]
Parameters:
  • log_to_console (bool, optional) – If True, the logger will output its contents to the python console. Defaults to True.

  • log_to_file (bool, optional) – If True, the logger will output its contents to a log file. Defaults to False.

  • logging_level (KnitScript_Logging_Level, optional) – The logging level of this logger. Defaults to logging information.

  • log_name (str, optional) – The name of the logger and the log file produced. Defaults to “KnitScript”.

property is_critical: bool

Returns: bool: True if this logs critical messages, False otherwise.

property is_debug: bool

Returns: bool: True if this logs debug messages, False otherwise.

property is_error: bool

Returns: bool: True if this logs error messages, False otherwise.

property is_info: bool

Returns: bool: True if this logs info messages, False otherwise.

property is_warning: bool

Returns: bool: True if this logs warning messages, False otherwise.

property name: str

Returns: str: The name of this logger.

print(message)

Prints the given message using this logger at the set level. If this is the first message printed by the logger, it will add a start line to the output. :param message: The message to print. :type message: str