log_utils.py


Overview

log_utils.py is a utility module designed to facilitate consistent and robust logging across the InfiniFlow project. It provides functions to initialize the root logger with configurable log file handling, console output, and dynamic log level settings. The module ensures that logs are rotated to prevent excessive file sizes and supports environment-driven log level customization for different packages. Additionally, it offers a helper function to log exceptions along with contextual messages.

By encapsulating logging setup and exception logging logic, this module promotes standardized logging practices, aiding in debugging, monitoring, and maintenance of the application.


Detailed Documentation

Global Variables


Functions

get_project_base_directory() -> str

Returns the absolute path to the base directory of the project by traversing two levels up from the current file's location.


init_root_logger(logfile_basename: str, log_format: str = "%(asctime)-15s %(levelname)-8s %(process)d %(message)s") -> None

Initializes the root logger with two handlers: a rotating file handler and a console stream handler. Supports dynamic log levels per package via the environment variable LOG_LEVELS.


log_exception(e: Exception, *args) -> None

Logs an exception with traceback and additional context messages or objects, then re-raises the original exception.


Implementation and Algorithm Notes


Interaction with Other Parts of the System


Visual Diagram

flowchart TD
    A[get_project_base_directory]
    B[init_root_logger]
    C[log_exception]

    B -->|calls| A
    B -->|sets up| D[Root Logger]
    B -->|adds| E[RotatingFileHandler]
    B -->|adds| F[StreamHandler]
    B -->|reads| G[Environment Variable LOG_LEVELS]
    B -->|sets levels for| H[Package Loggers (peewee, pdfminer, root)]
    C -->|logs| D

Summary

The log_utils.py module is a foundational utility for managing logging in the InfiniFlow project. It provides a streamlined way to initialize the root logger with file rotation, console output, and environment-driven log levels, while also offering a robust exception logging function that captures and enriches error information. This utility ensures that logs are both manageable and informative, facilitating easier debugging and operational insight.