From e28bc37e41c0a6db6251014e10f8fe7deb8f4d7c Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Thu, 3 Jul 2025 21:54:25 +0400 Subject: [PATCH] enh: AUDIT_UVICORN_LOGGER_NAMES --- backend/open_webui/env.py | 8 ++++++++ backend/open_webui/utils/logger.py | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/backend/open_webui/env.py b/backend/open_webui/env.py index 17691c3cf5..4db919121a 100644 --- a/backend/open_webui/env.py +++ b/backend/open_webui/env.py @@ -569,6 +569,14 @@ if OFFLINE_MODE: AUDIT_LOGS_FILE_PATH = f"{DATA_DIR}/audit.log" # Maximum size of a file before rotating into a new log file AUDIT_LOG_FILE_ROTATION_SIZE = os.getenv("AUDIT_LOG_FILE_ROTATION_SIZE", "10MB") + +# Comma separated list of logger names to use for audit logging +# Default is "uvicorn.access" which is the access log for Uvicorn +# You can add more logger names to this list if you want to capture more logs +AUDIT_UVICORN_LOGGER_NAMES = os.getenv( + "AUDIT_UVICORN_LOGGER_NAMES", "uvicorn.access" +).split(",") + # METADATA | REQUEST | REQUEST_RESPONSE AUDIT_LOG_LEVEL = os.getenv("AUDIT_LOG_LEVEL", "NONE").upper() try: diff --git a/backend/open_webui/utils/logger.py b/backend/open_webui/utils/logger.py index 2557610060..a21df2756b 100644 --- a/backend/open_webui/utils/logger.py +++ b/backend/open_webui/utils/logger.py @@ -5,7 +5,9 @@ from typing import TYPE_CHECKING from loguru import logger + from open_webui.env import ( + AUDIT_UVICORN_LOGGER_NAMES, AUDIT_LOG_FILE_ROTATION_SIZE, AUDIT_LOG_LEVEL, AUDIT_LOGS_FILE_PATH, @@ -128,11 +130,13 @@ def start_logger(): logging.basicConfig( handlers=[InterceptHandler()], level=GLOBAL_LOG_LEVEL, force=True ) + for uvicorn_logger_name in ["uvicorn", "uvicorn.error"]: uvicorn_logger = logging.getLogger(uvicorn_logger_name) uvicorn_logger.setLevel(GLOBAL_LOG_LEVEL) uvicorn_logger.handlers = [] - for uvicorn_logger_name in ["uvicorn.access"]: + + for uvicorn_logger_name in AUDIT_UVICORN_LOGGER_NAMES: uvicorn_logger = logging.getLogger(uvicorn_logger_name) uvicorn_logger.setLevel(GLOBAL_LOG_LEVEL) uvicorn_logger.handlers = [InterceptHandler()]