Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions backend/app/logging/setup_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,14 @@ def emit(self, record: logging.LogRecord) -> None:
Args:
record: The log record to process
"""
# Get the appropriate module name
# 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]
Comment on lines +238 to 246
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.


# Create a message that includes the original module in the format
Expand Down
9 changes: 7 additions & 2 deletions sync-microservice/app/logging/setup_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,14 @@ def emit(self, record: logging.LogRecord) -> None:
Args:
record: The log record to process
"""
# Get the appropriate module name
# 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]

# Create a message that includes the original module in the format
Expand Down
Loading