Module isotope.utils.logging

Utility functions for logging.

This module provides a function to setup the logger for logging messages to the terminal window and/or a file. It provides a unified logging format for all the modules in the package and should be used in other related packages, such as unit2_controller, to maintain consistency in logging. The name of the logger should be the name of the package.

Notes

You only need to setup the logger once in the main module of the package. The logger can be retrieved in other modules by calling logging.getLogger(__package__) to get the logger instance.

Examples

from isotope.utils.logging import setup_logger

logger = setup_logger(__package__)
logger.info('This is an info message.')
logger.debug('This is a debug message.')
logger.warning('This is a warning message.')
logger.error('This is an error message.')

# You may setup the logger with different levels for the terminal and file.
# It logs all levels equal or higher than the set level.
import logging
logger = setup_logger('unit2_controller', logging.INFO, logging.DEBUG)

# Avaliable log levels from the highest to the lowest:
# CRITICAL = 50
# FATAL = CRITICAL
# ERROR = 40
# WARNING = 30
# WARN = WARNING
# INFO = 20
# DEBUG = 10
# NOTSET = 0

# Setting the level to None will disable the logging for that handler.
logger = setup_logger('unit2_controller', logging.INFO, None)

Functions

def setup_logger(name: str = 'isotope', screen_level: int | None = 30, file_level: int | None = 10, log_file: int | None = None) ‑> logging.Logger

Setup logger for the package.

Args

name : str, optional
Name of the logger to use. Defaults to 'isotope'.
screen_level : [int | None], optional
level of logging to be displayed in the terminal. Set to None to disable. Defaults to logging.WARN.
file_level : [int | None], optional
level of logging to be logged in file. Set to None to disable. Defaults to logging.DEBUG.
log_file : [int | None], optional
name of the file. Defaults to the name of the logger.

Returns

logging.Logger
Logger instance.