-
Notifications
You must be signed in to change notification settings - Fork 456
feat: logger inheritance #99
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
feat: logger inheritance #99
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.
|
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>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Superb work overall. Can't wait to use it!
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
|
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 |
|
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>
.
|
Documents new Logger feature to support logging inheritance using the new `child` parameter.
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.