-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(logger): document enriching logs with logrecord attributes (#1271)
Co-authored-by: Heitor Lessa <lessa@amazon.com>
- Loading branch information
1 parent
94de494
commit e8f9ad1
Showing
4 changed files
with
58 additions
and
5 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[ | ||
{ | ||
"level": "INFO", | ||
"location": "<module>:16", | ||
"message": "Name should be equal service value", | ||
"name": "payment", | ||
"service": "payment", | ||
"timestamp": "2022-07-01 07:09:46,330+0000" | ||
}, | ||
{ | ||
"level": "INFO", | ||
"location": "<module>:23", | ||
"message": "This will include process ID and name", | ||
"name": "payment", | ||
"process": "9", | ||
"processName": "MainProcess", | ||
"service": "payment", | ||
"timestamp": "2022-07-01 07:09:46,330+0000" | ||
} | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from aws_lambda_powertools import Logger | ||
|
||
logger = Logger(service="payment", name="%(name)s") | ||
|
||
logger.info("Name should be equal service value") | ||
|
||
additional_log_attributes = {"process": "%(process)d", "processName": "%(processName)s"} | ||
logger.append_keys(**additional_log_attributes) | ||
logger.info("This will include process ID and name") | ||
logger.remove_keys(["processName"]) | ||
|
||
# further messages will not include processName |
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