[GH-ISSUE #16700] feat: Add File-Based Logging Support #18014

Closed
opened 2026-04-19 23:54:54 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @kim-seokjin on GitHub (Aug 18, 2025).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/16700

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

Originally created by @kim-seokjin on GitHub (Aug 18, 2025). Original GitHub issue: https://github.com/open-webui/open-webui/issues/16700 ### Check Existing Issues - [x] 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. - Related code: [open-webui/backend/open_webui/env.py](https://github.com/open-webui/open-webui/blob/438e5d966f0f64f9ea3feab22724a5bd96a4127b/backend/open_webui/env.py#L71) - Documentation: [Logging in Open WebUI](https://docs.openwebui.com/getting-started/advanced-topics/logging/#%EF%B8%8F-application-serverbackend-logging-python) **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`): ```python # 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](https://docs.python.org/3/library/logging.handlers.html#timedrotatingfilehandler) ### Alternatives Considered _No response_ ### Additional Context _No response_
Author
Owner

@tjbck commented on GitHub (Aug 18, 2025):

Refer to our loguru implementation.

<!-- gh-comment-id:3196422520 --> @tjbck commented on GitHub (Aug 18, 2025): Refer to our loguru implementation.
Author
Owner

@kim-seokjin commented on GitHub (Aug 19, 2025):

Thanks a lot for pointing this out. I learned something new because of you! @tjbck

After looking into logger.py, env.py, and audit.py, it seems that setting AUDIT_LOG_LEVEL in the .env file to one of "METADATA", "REQUEST", or "REQUEST_RESPONSE" should work. Could you confirm if that’s correct?

<!-- gh-comment-id:3198800542 --> @kim-seokjin commented on GitHub (Aug 19, 2025): Thanks a lot for pointing this out. I learned something new because of you! @tjbck After looking into [logger.py](https://github.com/open-webui/open-webui/blob/438e5d966f0f64f9ea3feab22724a5bd96a4127b/backend/open_webui/utils/logger.py#L135), [env.py](https://github.com/open-webui/open-webui/blob/438e5d966f0f64f9ea3feab22724a5bd96a4127b/backend/open_webui/env.py#L661), and [audit.py](https://github.com/open-webui/open-webui/blob/438e5d966f0f64f9ea3feab22724a5bd96a4127b/backend/open_webui/utils/audit.py#L53), it seems that setting `AUDIT_LOG_LEVEL` in the `.env` file to one of `"METADATA"`, `"REQUEST"`, or `"REQUEST_RESPONSE"` should work. Could you confirm if that’s correct?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#18014