Skip to content

Add structured logging across the codebase #90

@ajshedivy

Description

@ajshedivy

Summary

The codebase has inconsistent and minimal logging. The synchronous SQLJob path has zero logging — it uses print() on errors (e.g., sql_job.py:122). The async PoolJob has only 8 logger.debug() calls scoped to a misleading websockets.client logger name. No other modules (Connection, Cursor, Query, Pool management) emit any log messages.

This makes production debugging, performance analysis, and operational monitoring extremely difficult.

Current State

  • Sync code (SQLJob, Query, Connection, Cursor): No logging at all
  • SQLJob.connect(): Uses print(f"an error occured while loading connect result: {e}") — a bare print() in production code
  • Async code (PoolJob): 8 logger.debug() calls using getLogger("websockets.client") — a misleading logger name
  • Pool scaling decisions: Not logged (when connections are added/removed)
  • Query lifecycle: Not logged (prepare, execute, fetch, close)
  • Error paths: Errors are raised but not logged before propagation

Proposed Changes

  1. Add a consistent logging hierarchy using Python's logging module:

    • mapepire_python (root)
    • mapepire_python.client (SQLJob, Query)
    • mapepire_python.pool (Pool, PoolJob, PoolQuery)
    • mapepire_python.core (Connection, Cursor)
    • mapepire_python.auth (Kerberos, authentication)
  2. Replace all print() calls with proper logger.error() / logger.warning()

  3. Add logging at key lifecycle points:

    • INFO: Connection opened/closed, pool scaled up/down
    • DEBUG: Query prepared/executed/fetched/closed, message sent/received
    • WARNING: Connection dropped, retry attempted, pool exhaustion approaching
    • ERROR: Authentication failure, query failure, connection failure
  4. Ensure no sensitive data is logged (passwords, tokens, etc.)

Files to Modify

  • mapepire_python/client/sql_job.py — Replace print(), add connection lifecycle logging
  • mapepire_python/client/query.py — Add query lifecycle logging
  • mapepire_python/pool/pool_client.py — Add pool scaling/management logging
  • mapepire_python/pool/pool_job.py — Fix logger name, add consistent logging
  • mapepire_python/pool/pool_query.py — Add async query logging
  • mapepire_python/core/connection.py — Add connection open/close logging
  • mapepire_python/core/cursor.py — Add cursor operation logging
  • mapepire_python/authentication/kerberosTokenProvider.py — Add auth logging (no secrets)

Acceptance Criteria

  • All print() calls in production code are replaced with proper logging
  • Every module uses logging.getLogger(__name__) for its logger
  • Connection open/close events logged at INFO level
  • Query execution logged at DEBUG level
  • Pool scaling events logged at INFO level
  • Error paths logged at ERROR level before exception propagation
  • No passwords, tokens, or credentials appear in log output
  • Existing tests still pass

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions