Skip to content

Commit ae76d69

Browse files
Copilottmikula-dev
andcommitted
Fix code review issues - use instance logger instead of global
- Changed all logger.debug() calls to self.logger.debug() - Removed unused global logger initialization - All tests pass, pylint 10.00/10, mypy clean Co-authored-by: tmikula-dev <72911271+tmikula-dev@users.noreply.github.com>
1 parent b9849d9 commit ae76d69

1 file changed

Lines changed: 6 additions & 11 deletions

File tree

src/handlers/handler_health.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,11 @@
1919
"""
2020
import json
2121
import logging
22-
import os
2322
from datetime import datetime, timezone
2423
from typing import Dict, Any
2524

2625
from src.writers import writer_eventbridge, writer_kafka, writer_postgres
2726

28-
logger = logging.getLogger(__name__)
29-
log_level = os.environ.get("LOG_LEVEL", "INFO")
30-
logger.setLevel(log_level)
31-
3227

3328
class HandlerHealth:
3429
"""
@@ -59,7 +54,7 @@ def get_health(self) -> Dict[str, Any]:
5954
- 200: All dependencies healthy
6055
- 503: One or more dependencies not initialized
6156
"""
62-
logger.debug("Handling GET Health")
57+
self.logger.debug("Handling GET Health")
6358

6459
details: Dict[str, str] = {}
6560
all_healthy = True
@@ -69,14 +64,14 @@ def get_health(self) -> Dict[str, Any]:
6964
if not all(key in kafka_state for key in ["logger", "producer"]):
7065
details["kafka"] = "not_initialized"
7166
all_healthy = False
72-
logger.debug("Kafka writer not properly initialized")
67+
self.logger.debug("Kafka writer not properly initialized")
7368

7469
# Check EventBridge writer STATE
7570
eventbridge_state = writer_eventbridge.STATE
7671
if not all(key in eventbridge_state for key in ["logger", "client", "event_bus_arn"]):
7772
details["eventbridge"] = "not_initialized"
7873
all_healthy = False
79-
logger.debug("EventBridge writer not properly initialized")
74+
self.logger.debug("EventBridge writer not properly initialized")
8075

8176
# Check PostgreSQL writer - it uses global logger variable and POSTGRES dict
8277
# Just verify the module is accessible (init is always called in event_gate_lambda)
@@ -85,20 +80,20 @@ def get_health(self) -> Dict[str, Any]:
8580
except AttributeError:
8681
details["postgres"] = "not_initialized"
8782
all_healthy = False
88-
logger.debug("PostgreSQL writer not accessible")
83+
self.logger.debug("PostgreSQL writer not accessible")
8984

9085
# Calculate uptime
9186
uptime_seconds = int((datetime.now(timezone.utc) - self.start_time).total_seconds())
9287

9388
if all_healthy:
94-
logger.debug("Health check passed - all dependencies healthy")
89+
self.logger.debug("Health check passed - all dependencies healthy")
9590
return {
9691
"statusCode": 200,
9792
"headers": {"Content-Type": "application/json"},
9893
"body": json.dumps({"status": "ok", "uptime_seconds": uptime_seconds}),
9994
}
10095

101-
logger.debug("Health check degraded - some dependencies not initialized: %s", details)
96+
self.logger.debug("Health check degraded - some dependencies not initialized: %s", details)
10297
return {
10398
"statusCode": 503,
10499
"headers": {"Content-Type": "application/json"},

0 commit comments

Comments
 (0)