Skip to content

Commit e9a8712

Browse files
Fix naming inconsistency
1 parent fb6d1fa commit e9a8712

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

src/writer_kafka.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def write(topic_name: str, message: Dict[str, Any]) -> Tuple[bool, Optional[str]
9595
return True, None
9696

9797
log_payload_at_trace(logger, "Kafka", topic_name, message)
98-
98+
9999
errors: list[str] = []
100100
has_exception = False
101101

src/writer_postgres.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,20 @@ class PsycopgError(Exception): # type: ignore
4949

5050

5151
# Module level globals for typing
52-
_logger: logging.Logger = logging.getLogger(__name__)
52+
logger: logging.Logger = logging.getLogger(__name__)
5353
POSTGRES: Dict[str, Any] = {"database": ""}
5454

5555

56-
def init(logger: logging.Logger) -> None:
56+
def init(logger_instance: logging.Logger) -> None:
5757
"""Initialize Postgres credentials either from AWS Secrets Manager or fallback empty config.
5858
5959
Args:
60-
logger: Shared application logger.
60+
logger_instance: Shared application logger.
6161
"""
62-
global _logger # pylint: disable=global-statement
62+
global logger # pylint: disable=global-statement
6363
global POSTGRES # pylint: disable=global-statement
6464

65-
_logger = logger
65+
logger = logger_instance
6666

6767
secret_name = os.environ.get("POSTGRES_SECRET_NAME", "")
6868
secret_region = os.environ.get("POSTGRES_SECRET_REGION", "")
@@ -74,7 +74,7 @@ def init(logger: logging.Logger) -> None:
7474
else:
7575
POSTGRES = {"database": ""}
7676

77-
_logger.debug("Initialized POSTGRES writer")
77+
logger.debug("Initialized POSTGRES writer")
7878

7979

8080
def postgres_edla_write(cursor, table: str, message: Dict[str, Any]) -> None:
@@ -85,7 +85,7 @@ def postgres_edla_write(cursor, table: str, message: Dict[str, Any]) -> None:
8585
table: Target table name.
8686
message: Event payload.
8787
"""
88-
_logger.debug("Sending to Postgres - %s", table)
88+
logger.debug("Sending to Postgres - %s", table)
8989
cursor.execute(
9090
f"""
9191
INSERT INTO {table}
@@ -144,7 +144,7 @@ def postgres_run_write(cursor, table_runs: str, table_jobs: str, message: Dict[s
144144
table_jobs: Jobs table name.
145145
message: Event payload (includes jobs array).
146146
"""
147-
_logger.debug("Sending to Postgres - %s and %s", table_runs, table_jobs)
147+
logger.debug("Sending to Postgres - %s and %s", table_runs, table_jobs)
148148
cursor.execute(
149149
f"""
150150
INSERT INTO {table_runs}
@@ -224,7 +224,7 @@ def postgres_test_write(cursor, table: str, message: Dict[str, Any]) -> None:
224224
table: Target table name.
225225
message: Event payload.
226226
"""
227-
_logger.debug("Sending to Postgres - %s", table)
227+
logger.debug("Sending to Postgres - %s", table)
228228
cursor.execute(
229229
f"""
230230
INSERT INTO {table}
@@ -267,13 +267,13 @@ def write(topic_name: str, message: Dict[str, Any]) -> Tuple[bool, Optional[str]
267267
"""
268268
try:
269269
if not POSTGRES.get("database"):
270-
_logger.debug("No Postgres - skipping")
270+
logger.debug("No Postgres - skipping")
271271
return True, None
272272
if psycopg2 is None: # type: ignore
273-
_logger.debug("psycopg2 not available - skipping actual Postgres write")
273+
logger.debug("psycopg2 not available - skipping actual Postgres write")
274274
return True, None
275275

276-
log_payload_at_trace(_logger, "Postgres", topic_name, message)
276+
log_payload_at_trace(logger, "Postgres", topic_name, message)
277277

278278
with psycopg2.connect( # type: ignore[attr-defined]
279279
database=POSTGRES["database"],
@@ -291,13 +291,13 @@ def write(topic_name: str, message: Dict[str, Any]) -> Tuple[bool, Optional[str]
291291
postgres_test_write(cursor, "public_cps_za_test", message)
292292
else:
293293
msg = f"unknown topic for postgres {topic_name}"
294-
_logger.error(msg)
294+
logger.error(msg)
295295
return False, msg
296296

297297
connection.commit() # type: ignore
298298
except (RuntimeError, PsycopgError) as e: # narrowed exception set
299299
err_msg = f"The Postgres writer with failed unknown error: {str(e)}"
300-
_logger.error(err_msg)
300+
logger.error(err_msg)
301301
return False, err_msg
302302

303303
return True, None

tests/test_trace_logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def connect(self, **kwargs): # noqa: D401
7676

7777
logger = logging.getLogger("trace.postgres")
7878
logger.setLevel(TRACE_LEVEL)
79-
wp._logger = logger # type: ignore
79+
wp.logger = logger
8080
wp.POSTGRES = {"database": "db", "host": "h", "user": "u", "password": "p", "port": 5432}
8181

8282
caplog.set_level(TRACE_LEVEL)

0 commit comments

Comments
 (0)