logger: make CommonLogger a singleton#329
Merged
Merged
Conversation
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.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What
Makes
CommonLoggeran explicit singleton:CommonLogger()returns one shared instance via__new__, so it is configured once and everylogger.log(...)call reuses it.Builds on the callback +
RedactionFilterwork 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+ classmethods), so the singleton makes the instance match that model rather than newing one up perlog().LOG_FORMAT/LOG_LEVELare still read perlog()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.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.