Skip to content

fix: label uvicorn logs without error tag#1296

Closed
rdone4425 wants to merge 1 commit into
AOSSIE-Org:mainfrom
rdone4425:fix/uvicorn-log-tag
Closed

fix: label uvicorn logs without error tag#1296
rdone4425 wants to merge 1 commit into
AOSSIE-Org:mainfrom
rdone4425:fix/uvicorn-log-tag

Conversation

@rdone4425
Copy link
Copy Markdown

@rdone4425 rdone4425 commented May 28, 2026

Summary

  • Keep Uvicorn lifecycle logs tagged as [uvicorn] instead of deriving [error] from uvicorn.error
  • Apply the same logging tag fix to both backend and sync-microservice intercept handlers

Test Plan

  • python3 -m py_compile backend/app/logging/setup_logging.py sync-microservice/app/logging/setup_logging.py
  • Manual LogRecord verification for uvicorn.error confirms output contains [uvicorn] and not [error]

Closes #1172

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Improved logging output formatting to more accurately label Uvicorn-related logs, ensuring clearer and more consistent log identification across services.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 28, 2026

Walkthrough

Updated logging module name derivation in both backend/app/logging/setup_logging.py and sync-microservice/app/logging/setup_logging.py to special-case Uvicorn-origin loggers. The InterceptHandler.emit() method now maps logger names starting with "uvicorn" directly to the "uvicorn" module label instead of falling back to the last dotted segment, fixing misleading error-level tags on Uvicorn startup logs.

Changes

Uvicorn logger naming fix

Layer / File(s) Summary
Module label derivation for Uvicorn loggers
backend/app/logging/setup_logging.py, sync-microservice/app/logging/setup_logging.py
InterceptHandler.emit() adds explicit special-case handling for loggers starting with "uvicorn", mapping them to the module label "uvicorn" instead of extracting the last dotted component, while preserving the dotted-name fallback for all other logger names.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • AOSSIE-Org/PictoPy#940: Initial refactoring of InterceptHandler that introduced the uvicorn naming regression this PR fixes.

Suggested labels

Python

Suggested reviewers

  • rahulharpal1603

Poem

🐰 A logger once cried "error!" with fright,
When Uvicorn's startup logs came out right.
But now with this fix, dear rabbit knows true,
"uvicorn" labels shine clear through and through! 🌟

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: fixing Uvicorn logs to be labeled correctly without the misleading error tag.
Linked Issues check ✅ Passed The code changes directly address issue #1172 by mapping Uvicorn loggers to a generic 'uvicorn' label instead of deriving 'error' from the logger name, preventing misleading error tags on startup logs.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the Uvicorn logging label issue in both backend and sync-microservice InterceptHandler implementations, with no unrelated modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added backend bug Something isn't working good first issue Good for newcomers labels May 28, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/app/logging/setup_logging.py`:
- Around line 238-246: The logging logic (notably InterceptHandler.emit and the
module_name normalization in setup_logging) is duplicated between
backend.app.logging.setup_logging and
sync-microservice.app.logging.setup_logging; extract the shared parts into a
single reusable utility module (e.g., shared_logging or common.logging) that
exposes InterceptHandler.emit behavior and any helper functions used to
normalize record.name (module_name), then update both setup_logging modules to
import and call those helpers instead of duplicating code; ensure public symbols
include InterceptHandler (or a factory that returns it) and a
normalize_module_name(record) helper so both services can replace their local
logic with imports and remain functionally identical.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: be592c1c-01bc-47bc-bf6b-e669b87221cb

📥 Commits

Reviewing files that changed from the base of the PR and between b88b61d and ae6a894.

📒 Files selected for processing (2)
  • backend/app/logging/setup_logging.py
  • sync-microservice/app/logging/setup_logging.py

Comment on lines +238 to 246
# Get the appropriate module name. Uvicorn uses logger names such as
# ``uvicorn.error`` for regular server lifecycle messages, so avoid
# reducing those names to just ``error`` because that makes INFO logs
# look like failures in the formatted output.
module_name = record.name
if "." in module_name:
if module_name.startswith("uvicorn"):
module_name = "uvicorn"
elif "." in module_name:
module_name = module_name.split(".")[-1]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major | 🏗️ Heavy lift

Significant code duplication across backend and sync-microservice.

The InterceptHandler.emit() logic (and the entire logging setup module) is duplicated between backend/app/logging/setup_logging.py and sync-microservice/app/logging/setup_logging.py. This violates the DRY principle and creates maintenance burden—any future logging fixes would need to be applied in both places.

Consider extracting the shared logging functionality into a common utilities module that both services can import.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/app/logging/setup_logging.py` around lines 238 - 246, The logging
logic (notably InterceptHandler.emit and the module_name normalization in
setup_logging) is duplicated between backend.app.logging.setup_logging and
sync-microservice.app.logging.setup_logging; extract the shared parts into a
single reusable utility module (e.g., shared_logging or common.logging) that
exposes InterceptHandler.emit behavior and any helper functions used to
normalize record.name (module_name), then update both setup_logging modules to
import and call those helpers instead of duplicating code; ensure public symbols
include InterceptHandler (or a factory that returns it) and a
normalize_module_name(record) helper so both services can replace their local
logic with imports and remain functionally identical.

@rohan-pandeyy
Copy link
Copy Markdown
Contributor

Everyone is required to ask for assignment before opening a respective PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend bug Something isn't working good first issue Good for newcomers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Uvicorn startup logs confusingly labeled as [error]

2 participants