feat: Add File-Based Logging Support

#16700

Issue Details

14 days ago
No assignee
SukJinKimSukJinKim
opened 14 days ago
Author

Check Existing Issues

  • I have searched the existing issues and discussions.

Problem Description

Description: Currently, Open WebUI only outputs logs to the console. This can be problematic in production environments where persistent, file-based logs are required for auditing, debugging, and monitoring.

Problem: Both the documentation and the codebase show that logging is configured only for console output. This limitation can be critical in operational environments where log persistence and rotation are necessary.

Desired Solution you'd like

Proposed Solution: Leverage Python’s built-in logging module with TimedRotatingFileHandler. This allows logs to be rotated daily (e.g., at midnight) and automatically removes files older than a set retention period (e.g., 100 days).

Example implementation(logging part in env.py):

# Load global log level from environment variable GLOBAL_LOG_LEVEL = os.environ.get("GLOBAL_LOG_LEVEL", "").upper() if GLOBAL_LOG_LEVEL not in logging.getLevelNamesMapping(): GLOBAL_LOG_LEVEL = "INFO" # Configure root logger logger = logging.getLogger() logger.setLevel(GLOBAL_LOG_LEVEL) # --- Console Handler (stdout) --- console_handler = logging.StreamHandler(sys.stdout) console_handler.setLevel(GLOBAL_LOG_LEVEL) # --- File Handler (rotate daily at midnight, keep 100 files) --- file_handler = TimedRotatingFileHandler( filename="logs/app.log", # Log file path when="midnight", # Rotate at midnight interval=1, # Rotate every 1 day backupCount=100, # Keep up to 100 log files encoding="utf-8" # Prevent encoding issues (e.g., Korean logs) ) file_handler.setLevel(GLOBAL_LOG_LEVEL) # --- Formatter --- formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(name)s - %(message)s") console_handler.setFormatter(formatter) file_handler.setFormatter(formatter) # --- Add handlers to logger --- logger.addHandler(console_handler) logger.addHandler(file_handler) # Example logger log = logging.getLogger(__name__) log.info(f"GLOBAL_LOG_LEVEL: {GLOBAL_LOG_LEVEL}")

Reference:

Python Docs – TimedRotatingFileHandler

Alternatives Considered

No response

Additional Context

No response