Note to first-time contributors: Please open a discussion post in Discussions and describe your changes before submitting a pull request.
Before submitting, make sure you've checked the following:
Target branch: Please verify that the pull request targets the dev branch.
Description: Provide a concise description of the changes made in this pull request.
Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
Documentation: Have you updated relevant documentation Open WebUI Docs, or other documentation sources?
Dependencies: Are there any new dependencies? Have you updated the dependency versions in the documentation?
Testing: Have you written and run sufficient tests for validating the changes?
Code review: Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
Prefix: To cleary categorize this pull request, prefix the pull request title, using one of the following:
BREAKING CHANGE: Significant changes that may affect compatibility
build: Changes that affect the build system or external dependencies
ci: Changes to our continuous integration processes or workflows
chore: Refactor, cleanup, or other non-functional code changes
docs: Documentation update or addition
feat: Introduces a new feature or enhancement to the codebase
fix: Bug fix or error correction
i18n: Internationalization or localization changes
perf: Performance improvement
refactor: Code restructuring for better maintainability, readability, or scalability
style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc.)
test: Adding missing tests or correcting existing tests
WIP: Work in progress, a temporary label for incomplete or ongoing work
Changelog Entry
Description
Added audit logging middleware and related logic to separate auditable events from standard logs.
Incorporated a new logging setup with Loguru.
Introduced an AuditLogger for structured, file-based audit logs and a middleware to capture request/response data selectively.
Added
AuditLoggerMiddleware to intercept requests/responses, truncate large payloads, and schedule background audit logs.
AuditLogger class that binds auditable=True for logging user actions and metadata.
Environment variables (ENABLE_AUDIT_LOGS, AUDIT_LOG_LEVEL, etc.) to control audit logging behaviour.
Changed
Updated the startup logging process to use Loguru sinks for both console and audit logs.
Intercepted standard library logs with a custom handler to ensure unified logging across the application.
Deprecated
None
Removed
None
Fixed
None
Security
None
Breaking Changes
None
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
## 📋 Pull Request Information
**Original PR:** https://github.com/open-webui/open-webui/pull/8509
**Author:** [@victorstevansuse](https://github.com/victorstevansuse)
**Created:** 1/13/2025
**Status:** ❌ Closed
**Base:** `dev` ← **Head:** `feat/audits`
---
### 📝 Commits (10+)
- [`e052038`](https://github.com/open-webui/open-webui/commit/e0520382bdc0fb8356ec1b426d5a6ca60d5e2e1c) feat: add audit logging to file
- [`770be67`](https://github.com/open-webui/open-webui/commit/770be671d2ab42e715f918056fc67c30d2d8a2e6) feat: add loguru dependency
- [`77fdccf`](https://github.com/open-webui/open-webui/commit/77fdccfe6ffc80b1f1693058afa386a59a7bcb6b) feat: add audit logging to file
- [`ed4af34`](https://github.com/open-webui/open-webui/commit/ed4af34fdee0502e4ad95e87dbe80bbd69ca384e) feat: add audit context
- [`417fd5a`](https://github.com/open-webui/open-webui/commit/417fd5a2c4be72d919300570d896f561a1d108c5) refactor: delete audits models file
- [`1e8a217`](https://github.com/open-webui/open-webui/commit/1e8a21777492c989b13d1e878de4df11a69cb6cc) refactor: change audit logging middleware to avoid streaming issues and use context manager
- [`a4fa929`](https://github.com/open-webui/open-webui/commit/a4fa929abbc1a1c63248c5216a22e49c5aee2124) refactor: simplify audit logger
- [`66c13c4`](https://github.com/open-webui/open-webui/commit/66c13c40e758106dafb045b8bd3095af730e4488) refactor: refactor log file output json
- [`24132d7`](https://github.com/open-webui/open-webui/commit/24132d73bad63d8d761b85c09bb61a238a762194) chore: add asgiref dependency for advanced ASGI types
- [`b08cf04`](https://github.com/open-webui/open-webui/commit/b08cf04c48d8a261397e7d6638fb24f288971f51) chore: delete audit clutter from main
### 📊 Changes
**6 files changed** (+201 additions, -2 deletions)
<details>
<summary>View changed files</summary>
📝 `backend/open_webui/env.py` (+9 -0)
📝 `backend/open_webui/main.py` (+17 -2)
➕ `backend/open_webui/models/audits.py` (+25 -0)
➕ `backend/open_webui/utils/audits.py` (+148 -0)
➕ `backend/open_webui/utils/logger.py` (+0 -0)
📝 `backend/requirements.txt` (+2 -0)
</details>
### 📄 Description
# Pull Request Checklist
### Note to first-time contributors: Please open a discussion post in [Discussions](https://github.com/open-webui/open-webui/discussions) and describe your changes before submitting a pull request.
**Before submitting, make sure you've checked the following:**
- [x] **Target branch:** Please verify that the pull request targets the `dev` branch.
- [x] **Description:** Provide a concise description of the changes made in this pull request.
- [ ] **Changelog:** Ensure a changelog entry following the format of [Keep a Changelog](https://keepachangelog.com/) is added at the bottom of the PR description.
- [ ] **Documentation:** Have you updated relevant documentation [Open WebUI Docs](https://github.com/open-webui/docs), or other documentation sources?
- [ ] **Dependencies:** Are there any new dependencies? Have you updated the dependency versions in the documentation?
- [x] **Testing:** Have you written and run sufficient tests for validating the changes?
- [x] **Code review:** Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
- [x] **Prefix:** To cleary categorize this pull request, prefix the pull request title, using one of the following:
- **BREAKING CHANGE**: Significant changes that may affect compatibility
- **build**: Changes that affect the build system or external dependencies
- **ci**: Changes to our continuous integration processes or workflows
- **chore**: Refactor, cleanup, or other non-functional code changes
- **docs**: Documentation update or addition
- **feat**: Introduces a new feature or enhancement to the codebase
- **fix**: Bug fix or error correction
- **i18n**: Internationalization or localization changes
- **perf**: Performance improvement
- **refactor**: Code restructuring for better maintainability, readability, or scalability
- **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc.)
- **test**: Adding missing tests or correcting existing tests
- **WIP**: Work in progress, a temporary label for incomplete or ongoing work
# Changelog Entry
### Description
- Added audit logging middleware and related logic to separate auditable events from standard logs.
- Incorporated a new logging setup with `Loguru`.
- Introduced an `AuditLogger` for structured, file-based audit logs and a middleware to capture request/response data selectively.
### Added
- **`AuditLoggerMiddleware`** to intercept requests/responses, truncate large payloads, and schedule background audit logs.
- **`AuditLogger`** class that binds `auditable=True` for logging user actions and metadata.
- Environment variables (`ENABLE_AUDIT_LOGS`, `AUDIT_LOG_LEVEL`, etc.) to control audit logging behaviour.
### Changed
- Updated the startup logging process to use `Loguru` sinks for both console and audit logs.
- Intercepted standard library logs with a custom handler to ensure unified logging across the application.
### Deprecated
- None
### Removed
- None
### Fixed
- None
### Security
- None
### Breaking Changes
- None
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/8509
Author: @victorstevansuse
Created: 1/13/2025
Status: ❌ Closed
Base:
dev← Head:feat/audits📝 Commits (10+)
e052038feat: add audit logging to file770be67feat: add loguru dependency77fdccffeat: add audit logging to fileed4af34feat: add audit context417fd5arefactor: delete audits models file1e8a217refactor: change audit logging middleware to avoid streaming issues and use context managera4fa929refactor: simplify audit logger66c13c4refactor: refactor log file output json24132d7chore: add asgiref dependency for advanced ASGI typesb08cf04chore: delete audit clutter from main📊 Changes
6 files changed (+201 additions, -2 deletions)
View changed files
📝
backend/open_webui/env.py(+9 -0)📝
backend/open_webui/main.py(+17 -2)➕
backend/open_webui/models/audits.py(+25 -0)➕
backend/open_webui/utils/audits.py(+148 -0)➕
backend/open_webui/utils/logger.py(+0 -0)📝
backend/requirements.txt(+2 -0)📄 Description
Pull Request Checklist
Note to first-time contributors: Please open a discussion post in Discussions and describe your changes before submitting a pull request.
Before submitting, make sure you've checked the following:
devbranch.Changelog Entry
Description
Loguru.AuditLoggerfor structured, file-based audit logs and a middleware to capture request/response data selectively.Added
AuditLoggerMiddlewareto intercept requests/responses, truncate large payloads, and schedule background audit logs.AuditLoggerclass that bindsauditable=Truefor logging user actions and metadata.ENABLE_AUDIT_LOGS,AUDIT_LOG_LEVEL, etc.) to control audit logging behaviour.Changed
Logurusinks for both console and audit logs.Deprecated
Removed
Fixed
Security
Breaking Changes
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.