[PR #409] [MERGED] Centralize and modernize backend logging with Loguru and configurable sinks #712

Closed
opened 2026-03-13 21:05:20 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/AJaySi/ALwrity/pull/409
Author: @AJaySi
Created: 3/11/2026
Status: Merged
Merged: 3/12/2026
Merged by: @AJaySi

Base: mainHead: codex/review-logging_config.py-for-improvements


📝 Commits (1)

  • 7619604 Harden logging config with safer overrides and optional JSON/file sinks

📊 Changes

6 files changed (+287 additions, -124 deletions)

View changed files

📝 backend/api/linkedin_image_generation.py (+1 -3)
📝 backend/app.py (+2 -2)
📝 backend/logging_config.py (+280 -110)
📝 backend/main.py (+2 -2)
📝 backend/services/llm_providers/gemini_provider.py (+0 -5)
📝 backend/start_alwrity_backend.py (+2 -2)

📄 Description

Motivation

  • Replace ad-hoc, noisy logging setup with a single, production-ready logging configuration using loguru for clearer, consistent output and easier diagnostics.
  • Provide environment-driven overrides and options (JSON output, file rotation, per-logger levels, video-focused sink) to support both developer and end-user use cases.
  • Ensure stdlib logging and popular server loggers are intercepted and routed into the unified system for coherent logs across modules.

Description

  • Rewrote backend/logging_config.py to implement configure_logging(...) which configures loguru sinks, stdlib interception via InterceptHandler, per-logger overrides from ALWRITY_LOG_LEVEL_OVERRIDES, optional JSON formatting, file rotation/retention, and uncaught exception hooks.
  • Added helpers bind_logger_context(...) and a backward-compatible setup_clean_logging() wrapper to preserve existing import sites.
  • Updated bootstrap code in backend/app.py, backend/main.py, and backend/start_alwrity_backend.py to call configure_logging(...) with a bootstrap_source instead of the previous setup_clean_logging().
  • Adjusted modules to use the centralized logger approach: backend/api/linkedin_image_generation.py now uses loguru's logger, and backend/services/llm_providers/gemini_provider.py uses a service-specific get_service_logger and improved .env loading logic while removing ad-hoc basicConfig usage.

Testing

  • No automated tests were run as part of this change.

Codex Task


🔄 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/AJaySi/ALwrity/pull/409 **Author:** [@AJaySi](https://github.com/AJaySi) **Created:** 3/11/2026 **Status:** ✅ Merged **Merged:** 3/12/2026 **Merged by:** [@AJaySi](https://github.com/AJaySi) **Base:** `main` ← **Head:** `codex/review-logging_config.py-for-improvements` --- ### 📝 Commits (1) - [`7619604`](https://github.com/AJaySi/ALwrity/commit/7619604324e72e7b366b749648dcefb1cbcf153a) Harden logging config with safer overrides and optional JSON/file sinks ### 📊 Changes **6 files changed** (+287 additions, -124 deletions) <details> <summary>View changed files</summary> 📝 `backend/api/linkedin_image_generation.py` (+1 -3) 📝 `backend/app.py` (+2 -2) 📝 `backend/logging_config.py` (+280 -110) 📝 `backend/main.py` (+2 -2) 📝 `backend/services/llm_providers/gemini_provider.py` (+0 -5) 📝 `backend/start_alwrity_backend.py` (+2 -2) </details> ### 📄 Description ### Motivation - Replace ad-hoc, noisy logging setup with a single, production-ready logging configuration using `loguru` for clearer, consistent output and easier diagnostics. - Provide environment-driven overrides and options (JSON output, file rotation, per-logger levels, video-focused sink) to support both developer and end-user use cases. - Ensure stdlib logging and popular server loggers are intercepted and routed into the unified system for coherent logs across modules. ### Description - Rewrote `backend/logging_config.py` to implement `configure_logging(...)` which configures `loguru` sinks, stdlib interception via `InterceptHandler`, per-logger overrides from `ALWRITY_LOG_LEVEL_OVERRIDES`, optional JSON formatting, file rotation/retention, and uncaught exception hooks. - Added helpers `bind_logger_context(...)` and a backward-compatible `setup_clean_logging()` wrapper to preserve existing import sites. - Updated bootstrap code in `backend/app.py`, `backend/main.py`, and `backend/start_alwrity_backend.py` to call `configure_logging(...)` with a `bootstrap_source` instead of the previous `setup_clean_logging()`. - Adjusted modules to use the centralized logger approach: `backend/api/linkedin_image_generation.py` now uses `loguru`'s `logger`, and `backend/services/llm_providers/gemini_provider.py` uses a service-specific `get_service_logger` and improved `.env` loading logic while removing ad-hoc `basicConfig` usage. ### Testing - No automated tests were run as part of this change. ------ [Codex Task](https://chatgpt.com/codex/tasks/task_e_69b123e7da448328aeed5fe11c3e2814) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-13 21:05:20 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ALwrity#712
No description provided.