feat: logger inheritance#99
Merged
heitorlessa merged 20 commits intoaws-powertools:developfrom Aug 14, 2020
Merged
Conversation
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Codecov Report
@@ Coverage Diff @@
## develop #99 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 17 17
Lines 467 497 +30
Branches 42 45 +3
=========================================
+ Hits 467 497 +30
Continue to review full report at Codecov.
|
nmoutschen
reviewed
Aug 10, 2020
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
alexanderluiscampino
left a comment
There was a problem hiding this comment.
Superb work overall. Can't wait to use it!
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Contributor
Author
|
Just addressed @alexanderluiscampino commentson consistency, and took the opportunity to turn I'll start working on the docs this afternoon or tomorrow, and should release a minor version by EOW |
Contributor
Author
|
Yep it’s fixed in the latest commit ;)
…On Wed, 12 Aug 2020 at 09:32, Alexandre Campino ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In aws_lambda_powertools/logging/logger.py
<#99 (comment)>
:
> @@ -118,7 +118,7 @@ def __init__(
):
self.service = service or os.getenv("POWERTOOLS_SERVICE_NAME") or "service_undefined"
self.sampling_rate = sampling_rate or os.getenv("POWERTOOLS_LOGGER_SAMPLE_RATE") or 0.0
- self.log_level = level or os.getenv("LOG_LEVEL") or logging.INFO
+ self.log_level = level or os.getenv("LOG_LEVEL".upper()) or logging.INFO
Gotcha, your explanation makes sense, then you need the .upper outside of
the getenv(LOG_LEVEL).UPPER()
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
<#99 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAZPQBH7FMGNN2SRN76WK2TSAJAQDANCNFSM4PZATT2Q>
.
|
to-mc
approved these changes
Aug 12, 2020
Documents new Logger feature to support logging inheritance using the new `child` parameter.
6 tasks
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.
Issue #, if available: #97
Description of changes:
This addresses a common issue when trying to use
Loggeracross multiple modules while wanting to:For this, we've introduced a new parameter,
child, when initializing a new Logger, and some internal changes while keeping the same UX and backwards compatibility.._loggerUX
Key aspects:
childparameter, and theLoggerwill be named after<service>.<caller_file_name>Loggerwith the sameservicename (explicit or via environment variable) returns the sameLoggerLoggeror ParentLoggerwill be propagated to all instancesCreating a child Logger
Child logger can be created in any other as long as a parent is created too - This supports customers using Layers or different file names to create child loggers.
Reusing the same Logger
Checklist
Changes
getLoggerto allow inheritanceCreatenameparameter for hierarchyUseserviceifnameis emptyhandlerprivatelog_keysnameparameterchildboolean paramchildLoggerchildLoggers based on<service>.<caller_file_name>to mimickgetLogger(__name__)getRandomLoggerutility functionOptional
Benchmark
Quick checks as we've removed
logging.Loggersub-classing, respect Logging inheritance, and are proxying calls to inner Logger.Basic logger
python -m timeit -s 'from aws_lambda_powertools import Logger; logger = Logger(); logger.info("hello world")'Inheritance
python -m timeit -s 'from aws_lambda_powertools import Logger; logger = Logger(); l = Logger(); l.info("hello world")'python -m timeit -s 'from aws_lambda_powertools import Logger; logger = Logger(child=True); l = Logger(); l.info("hello world")'Breaking change checklist
RFC issue #:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.