Skip to content

refactor(logging): migrate service classes to centralized get_logger()#22

Open
Kunal-Somani wants to merge 1 commit intoruxailab:mainfrom
Kunal-Somani:refactor/migrate-services-to-get-logger
Open

refactor(logging): migrate service classes to centralized get_logger()#22
Kunal-Somani wants to merge 1 commit intoruxailab:mainfrom
Kunal-Somani:refactor/migrate-services-to-get-logger

Conversation

@Kunal-Somani
Copy link
Copy Markdown

Summary

Two service classes were directly calling coloredlogs.install() inside their __init__ methods:

  • EmotionsAnalysisImp.__init__()
  • FirebaseImp.__init__()

This caused the log handler to be reinstalled on every object instantiation, producing duplicate log entries whenever a new service instance was created during a request cycle.

Changes

services/emotion_analysis/emotion_analysis_imp.py

  • Removed coloredlogs.install() from __init__
  • Removed instance-level self.logger — replaced with module-level logger = get_logger(__name__) consistent with PR feat(logging): add centralized logger factory and replace print statements #21
  • Switched all f-string log calls to % formatting (Python logging best practice — skips string interpolation when the log level is disabled)
  • Removed unused logging and coloredlogs imports

services/data/firebase_imp.py

  • Removed coloredlogs.install() from __init__
  • Removed duplicate logger class attribute and instance reassignment
  • Added logger.debug() to the already-initialized path in _initialize_app() for better traceability
  • Added logger.info() to upload_to_firestore() on successful write
  • Removed unused logging and coloredlogs imports

Root Cause

Neither service was using the centralized get_logger() factory introduced in PR #21. This PR completes the migration so all modules share one consistent logging configuration controlled by the LOG_LEVEL env var.

- Remove coloredlogs.install() calls from EmotionsAnalysisImp.__init__()
  and FirebaseImp.__init__() — reinstalling the log handler on every
  object instantiation was causing duplicate log entries
- Replace instance-level self.logger with module-level logger via
  get_logger(__name__) for consistency with utils/logger.py (PR ruxailab#21)
- Switch all f-string log calls to % formatting (Python logging best
  practice — avoids string interpolation when log level is disabled)
- Add debug log to FirebaseImp._initialize_app() for the already-
  initialized path
- Add logger.info() to upload_to_firestore() on successful Firestore write
- Remove unused logging and coloredlogs imports from both files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant