Skip to content

logger: make CommonLogger a singleton#329

Merged
paulcruse3 merged 1 commit into
masterfrom
sweet-12-logger-singleton
Jun 17, 2026
Merged

logger: make CommonLogger a singleton#329
paulcruse3 merged 1 commit into
masterfrom
sweet-12-logger-singleton

Conversation

@paulcruse3

Copy link
Copy Markdown
Member

What

Makes CommonLogger an explicit singleton: CommonLogger() returns one shared instance via __new__, so it is configured once and every logger.log(...) call reuses it.

Builds on the callback + RedactionFilter work merged in #328.

Why

So callers configure the logger (register a RedactionFilter / other callbacks) once at startup and every subsequent log inherits it, without re-instantiating per call.

Notes

  • Callbacks were already global (class-level _callbacks + classmethods), so the singleton makes the instance match that model rather than newing one up per log().
  • LOG_FORMAT / LOG_LEVEL are still read per log() call, not cached in __init__. This is deliberate: caching them on a singleton would freeze the format/level for the process (and break the env-driven test suite). __init__ is guarded to run its one-time setup (jsonpickle config, level table) only once.
  • Backward compatible: logger.log(...) and output formats unchanged.

Validation

  • pytest tests/acai_aws: 610 passed (1 new: test_common_logger_is_singleton).
  • pylint acai_aws --recursive=y --fail-under 10: 10.00/10.

Part of SWEET-12.

CommonLogger now returns a single shared instance via __new__, so it is
configured once and every logger.log() call reuses it. Callbacks remain
class-level. LOG_FORMAT/LOG_LEVEL are still read per log() call (not
cached at init) so env-driven format/level continue to work.
@sonarqubecloud

Copy link
Copy Markdown

@paulcruse3 paulcruse3 merged commit e876123 into master Jun 17, 2026
9 checks passed
@paulcruse3 paulcruse3 deleted the sweet-12-logger-singleton branch June 17, 2026 03:16
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