Skip to content

netlist_carpentry.utils.log

Logging module for Netlist Carpentry, based on Python's logging module.

Classes:

  • Log

    Not very useful class. This is only to store some staticial information and

  • RichHandler

    Custom logging handler that renders output with Rich.

Functions:

Log

Not very useful class. This is only to store some staticial information and variables, which are needed for formatting purposes by the logger, so all messages start at the same column after the DEBUG/INFO/ERROR/... and module name entries.

Methods:

  • debug_highlighted

    Adds a highlighted DEBUG message to the logger.

  • debug

    Adds a DEBUG message to the logger.

  • info

    Adds an INFO message to the logger.

  • info_highlighted

    Adds a highlighted INFO message to the logger.

  • warn

    Adds a WARNING message to the logger.

  • error

    Adds an ERROR message to the logger.

  • fatal

    Adds a FATAL message to the logger.

  • mute

    Disable all following logging messages. Script outputs are still printed to

  • unmute

    Undoes the muting.

  • format_string

    Formats the given string to be a fancy console message with the name of the module

  • get_caller_name

    Returns the name of the caller module together with the calling function.

  • report

    Prints a summary of warnings and errors encountered up to this point during

Attributes:

  • file_path

    The path to the log file, where all log messages will be saved.

  • longest_caller_name

    This variable holds the length of the module name (plus package path) with

  • fatals_quantity

    How many fatal errors have been encountered during the run. Incremented

  • errors_quantity

    How many catched errors have been encountered during the run. Incremented

  • warns_quantity

    How many warnings have been encountered during the run. Incremented with

file_path class-attribute instance-attribute

file_path = ''

The path to the log file, where all log messages will be saved.

longest_caller_name class-attribute instance-attribute

longest_caller_name = 48

This variable holds the length of the module name (plus package path) with the most characters. This is needed for formatting purposes by the logger, so all messages start at the same column after the DEBUG/INFO/ERROR/ ... and module name entries.

fatals_quantity class-attribute instance-attribute

fatals_quantity = 0

How many fatal errors have been encountered during the run. Incremented with every fatal error encountered.

errors_quantity class-attribute instance-attribute

errors_quantity = 0

How many catched errors have been encountered during the run. Incremented with every catched error encountered.

warns_quantity class-attribute instance-attribute

warns_quantity = 0

How many warnings have been encountered during the run. Incremented with every warning encountered.

debug_highlighted

debug_highlighted(message: str) -> None

Adds a highlighted DEBUG message to the logger.

debug

debug(message: str) -> None

Adds a DEBUG message to the logger.

info

info(message: str) -> None

Adds an INFO message to the logger.

info_highlighted

info_highlighted(message: str) -> None

Adds a highlighted INFO message to the logger.

warn

warn(message: str) -> None

Adds a WARNING message to the logger.

error

error(message: str) -> None

Adds an ERROR message to the logger.

fatal

fatal(message: str) -> None

Adds a FATAL message to the logger.

mute

mute() -> None

Disable all following logging messages. Script outputs are still printed to the console.

unmute

unmute() -> None

Undoes the muting.

format_string

format_string(message: str) -> str

Formats the given string to be a fancy console message with the name of the module causing the message (if CFG.print_source_module is True), as well as the message itself. The modified message is then returned. If CFG.print_source_module is set to False, the original message is returned instead.

get_caller_name

get_caller_name(skip_frames: List[str] = ['log']) -> str

Returns the name of the caller module together with the calling function.

This is needed for printing log messages and determining the module sending the logging entry. skip_frames is a list of strings with the names of modules that should be excluded. For example:

Top Frame:  package1.module1.func1
2nd Frame:  package1.module1.func2
3rd Frame:  package1.module2.func3
skip_frames:["module1"]

In this case, the return value will be module2.func3, because the two top frames contain the excluded module. The main usage is the log module, for example:

Top Frame:  log.format_string
2nd Frame:  log.info
3rd Frame:  util.connect_two_instances
skip_frames:["log"]

In this case, the return value will be util.connect_two_instances, which is then used for the logger to print the source of the logging call.

report

report() -> None

Prints a summary of warnings and errors encountered up to this point during runtime. Can be called anytime to get information over the already encountered errors and warnings.

RichHandler

Bases: RichHandler

Custom logging handler that renders output with Rich.

Overrides formatting and adds custom levels.

Methods:

render_message

render_message(record: LogRecord, message: str) -> ConsoleRenderable

Render message text in to Text.

Applies style to message text for special levels.

initialize_logging

initialize_logging(
    output_dir: Optional[str] = None, custom_file_name: str = ""
) -> bool

Sets up the initial configuration for the logging module.

Parameters:

  • output_dir

    (Optional[str], default: None ) –

    The directory where log files will be saved. If None, no log file will be saved. Defaults to None.

  • custom_file_name

    (str, default: '' ) –

    A custom file name to use for logging. Defaults to an empty string, in which case the log file name will be generated based on on the current timestamp and log level.

Returns:

  • bool ( bool ) –

    Whether an error occurred during initialization.