Implementation:Infiniflow Ragflow Log Utils
| Knowledge Sources | |
|---|---|
| Domains | Logging, Infrastructure |
| Last Updated | 2026-02-12 06:00 GMT |
Overview
Concrete tool for centralized logging initialization with rotating file handlers and per-package log level control provided by the RAGFlow common library.
Description
The log_utils module provides init_root_logger which configures the Python root logger with rotating file handlers (1GB per file, 100 backups) and stream handlers, supporting per-package log level configuration via the LOG_LEVELS environment variable. The log_exception function logs exceptions with optional context arguments.
Usage
Call init_root_logger at application startup to initialize logging. Use log_exception in exception handlers for structured error logging.
Code Reference
Source Location
- Repository: Infiniflow_Ragflow
- File: common/log_utils.py
- Lines: 1-87
Signature
def init_root_logger(logfile_basename: str, log_format: str = ...) -> None:
"""Initialize root logger with rotating file and stream handlers."""
def log_exception(e: Exception, *args) -> None:
"""Log exception with context arguments and re-raise."""
Import
from common.log_utils import init_root_logger, log_exception
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| logfile_basename | str | Yes | Base name for the log file |
| log_format | str | No | Log message format string |
| e | Exception | Yes | Exception to log (for log_exception) |
Outputs
| Name | Type | Description |
|---|---|---|
| init_root_logger() returns | None | Configures global logging |
| log_exception() returns | None | Logs and re-raises exception |
Usage Examples
from common.log_utils import init_root_logger, log_exception
# Initialize at startup
init_root_logger("ragflow_server")
# Use in exception handler
try:
process_document(doc)
except Exception as e:
log_exception(e, "Failed to process document", doc.id)