Module llms_wrapper.log

Module to handle logging. This module is used to set up the logging for the entire package. NOTE: by default, loguru logging is disabled for the package (see init.py). To enable logging, a client of this library must setup its own logging configuration and enable logging for this package using logger.enable("llms_wrapper").

Functions

def configure_logging(level=None, logfile=None, format=None, enable=True)
Expand source code
def configure_logging(level=None, logfile=None, format=None, enable=True):
    """
    Configure loguru logging sinks. This removes the default sink and adds one for stderr and, if a logfile
    is specified, one for the logfile, both for the specified level. The format of the log messages can be
    specified with the format parameter or the default format is used.
    """
    logger.remove()
    if level is None:
        level = DEFAULT_LOGGING_LEVEL
    if format is None:
        format = DEFAULT_LOGGING_FORMAT
    logger.add(sys.stderr, level=level, format=format)
    if logfile is not None:
        logger.add(logfile, level=level, format=format)
    sys.excepthook = handle_exception
    if enable:
        logger.enable("llms_wrapper")

Configure loguru logging sinks. This removes the default sink and adds one for stderr and, if a logfile is specified, one for the logfile, both for the specified level. The format of the log messages can be specified with the format parameter or the default format is used.

def handle_exception(exc_type, exc_value, exc_traceback)
Expand source code
def handle_exception(exc_type, exc_value, exc_traceback):
    if issubclass(exc_type, KeyboardInterrupt):
        sys.__excepthook__(exc_type, exc_value, exc_traceback)
        return
    logger.opt(exception=(exc_type, exc_value, exc_traceback)).error("Unhandled exception")