-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix multiple handlers causing duplicate messages #43
Merged
markdboyd
merged 3 commits into
nasa:merge-nsidc-handlers-fix
from
nsidc:fix-multiple-handlers
Feb 15, 2022
Merged
Fix multiple handlers causing duplicate messages #43
markdboyd
merged 3 commits into
nasa:merge-nsidc-handlers-fix
from
nsidc:fix-multiple-handlers
Feb 15, 2022
Conversation
This file contains 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
markdboyd
approved these changes
Feb 15, 2022
This fixes the test added in the previous commit Before this change, multiple calls to `CumulusLogger(name)` would construct a `CumulusLogger` instance with the same underlying `Logger` instance, but each construction would also create and attach a new handler, resulting in duplicate messages, e.g.: ``` > python >>> from cumulus_logger import CumulusLogger >>> logger = CumulusLogger('test') >>> logger.info('hello there') {"message": "hello there", "timestamp": "2021-12-21T16:18:09.315309", "level": "info"} >>> >>> logger2 = CumulusLogger('test') >>> logger2.info('hello there') {"message": "hello there", "timestamp": "2021-12-21T16:18:16.845070", "level": "info"} {"message": "hello there", "timestamp": "2021-12-21T16:18:16.845070", "level": "info"} >>> >>> logger.info('hello there') {"message": "hello there", "timestamp": "2021-12-21T16:18:18.165564", "level": "info"} {"message": "hello there", "timestamp": "2021-12-21T16:18:18.165564", "level": "info"} ``` See also the screenshots on ghrcdaac/dmrpp-file-generator-docker#25 With this change, a new handler is only constructed if the underlying `Logger` does not already have any handlers, preventing messages from being handled more than once: ``` > python >>> from cumulus_logger import CumulusLogger >>> logger = CumulusLogger('test') >>> logger.info('hello there') {"message": "hello there", "timestamp": "2021-12-21T16:33:56.735453", "level": "info"} >>> >>> logger2 = CumulusLogger('test') >>> logger2.info('hello there') {"message": "hello there", "timestamp": "2021-12-21T16:34:03.887972", "level": "info"} >>> >>> logger.info('hello there') {"message": "hello there", "timestamp": "2021-12-21T16:34:07.808415", "level": "info"} ```
a58c63b
to
264682e
Compare
markdboyd
added a commit
that referenced
this pull request
Feb 15, 2022
* test_logger setup: allow kwargs to be forwarded to CumulusLogger constructor * add failing test, each logger should only have one handler * CumulusLogger: only create new handler if one is not present This fixes the test added in the previous commit Before this change, multiple calls to `CumulusLogger(name)` would construct a `CumulusLogger` instance with the same underlying `Logger` instance, but each construction would also create and attach a new handler, resulting in duplicate messages, e.g.: ``` > python >>> from cumulus_logger import CumulusLogger >>> logger = CumulusLogger('test') >>> logger.info('hello there') {"message": "hello there", "timestamp": "2021-12-21T16:18:09.315309", "level": "info"} >>> >>> logger2 = CumulusLogger('test') >>> logger2.info('hello there') {"message": "hello there", "timestamp": "2021-12-21T16:18:16.845070", "level": "info"} {"message": "hello there", "timestamp": "2021-12-21T16:18:16.845070", "level": "info"} >>> >>> logger.info('hello there') {"message": "hello there", "timestamp": "2021-12-21T16:18:18.165564", "level": "info"} {"message": "hello there", "timestamp": "2021-12-21T16:18:18.165564", "level": "info"} ``` See also the screenshots on ghrcdaac/dmrpp-file-generator-docker#25 With this change, a new handler is only constructed if the underlying `Logger` does not already have any handlers, preventing messages from being handled more than once: ``` > python >>> from cumulus_logger import CumulusLogger >>> logger = CumulusLogger('test') >>> logger.info('hello there') {"message": "hello there", "timestamp": "2021-12-21T16:33:56.735453", "level": "info"} >>> >>> logger2 = CumulusLogger('test') >>> logger2.info('hello there') {"message": "hello there", "timestamp": "2021-12-21T16:34:03.887972", "level": "info"} >>> >>> logger.info('hello there') {"message": "hello there", "timestamp": "2021-12-21T16:34:07.808415", "level": "info"} ``` Co-authored-by: Michael Brandt <michaelbrandt5@gmail.com>
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.
CumulusLogger
constructorCumulusLogger
instance for a givenname
should only have one handlerCumulusLogger
constructor: only create new handler if one is not presentBefore this change, multiple calls to
CumulusLogger(name)
would construct aCumulusLogger
instance with the same underlyingLogger
instance, but eachconstruction would also create and attach a new handler, resulting in duplicate
messages, e.g.:
See also the screenshots on ghrcdaac/dmrpp-file-generator-docker#25 to see duplicates in
CloudWatch. The dmrpp-generator code isn't doing anything out of the ordinary when
creating its
CumulusLogger
instance, which is what lead me to search here to find thecause of the duplication.
With this change, a new handler is only constructed if the underlying
Logger
does not already have any handlers, preventing messages from being handled more
than once: