mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 10:58:17 -05:00
[PR #21747] [MERGED] feat: add LOG_FORMAT=json for structured JSON logging #41889
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/21747
Author: @goto1134
Created: 2/22/2026
Status: ✅ Merged
Merged: 2/22/2026
Merged by: @tjbck
Base:
dev← Head:feat/json-logging📝 Commits (3)
39b8c94feat: add LOG_FORMAT env var with JSON formatter for early loggingeea1130feat: add JSON sink for Loguru when LOG_FORMAT=json922f854feat: suppress ASCII banner and fix alembic logging in JSON mode📊 Changes
4 files changed (+101 additions, -11 deletions)
View changed files
📝
backend/open_webui/env.py(+46 -1)📝
backend/open_webui/main.py(+3 -1)📝
backend/open_webui/migrations/env.py(+9 -1)📝
backend/open_webui/utils/logger.py(+43 -8)📄 Description
Changelog Entry
Description
LOG_FORMATenvironment variable — set tojsonto switch all stdout logging to single-line JSON objects suitable for log aggregators (Loki, Fluentd, CloudWatch, Datadog)Added
LOG_FORMATenvironment variable (jsonto enable, unset or any other value for default plain-text)JSONFormatterclass inenv.pyfor early stdlib logging (covers module imports, alembic migrations)_json_sink()Loguru sink inlogger.pyfor runtime loggingChanged
start_logger()conditionally uses JSON sink or plain-text format based onLOG_FORMATmigrations/env.pyre-appliesJSONFormatterafter alembic'sfileConfig()to preserve JSON logging during migrationsLOG_FORMAT=jsonto keep log stream parseableJSON log fields
tsleveldebug,info,warn,error,fatalmsgcallermodule:function:line(Loguru)extraerrorstacktraceExample output
Additional Information
LOG_FORMATset) is completely unchangedJSONFormatterhandles early startup logs before Loguru is initialized, then_json_sinktakes over afterstart_logger()runsContributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.