-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(logger): add clear_state method (#5956)
* feat(logger): add clear_state method to Logger * changes after feedback * change reset default keys --------- Co-authored-by: Leandro Damascena <[email protected]>
- Loading branch information
1 parent
6971eb2
commit 9b33d29
Showing
6 changed files
with
129 additions
and
2 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
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,7 @@ | ||
{ | ||
"level": "INFO", | ||
"location": "lambda_handler:126", | ||
"message": "State after clearing - only show default keys", | ||
"timestamp": "2025-01-30 13:56:03,158-0300", | ||
"service": "payment" | ||
} |
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 @@ | ||
{ | ||
"logs": [ | ||
{ | ||
"level": "INFO", | ||
"location": "lambda_handler:122", | ||
"message": "Starting order processing", | ||
"timestamp": "2025-01-30 13:56:03,157-0300", | ||
"service": "payment", | ||
"order_id": "12345" | ||
}, | ||
{ | ||
"level": "INFO", | ||
"location": "lambda_handler:124", | ||
"message": "Final state before clearing", | ||
"timestamp": "2025-01-30 13:56:03,157-0300", | ||
"service": "payment", | ||
"order_id": "12345" | ||
} | ||
] | ||
} |
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,15 @@ | ||
from aws_lambda_powertools import Logger | ||
from aws_lambda_powertools.utilities.typing import LambdaContext | ||
|
||
logger = Logger(service="payment", level="DEBUG") | ||
|
||
|
||
def lambda_handler(event: dict, context: LambdaContext) -> str: | ||
try: | ||
logger.append_keys(order_id="12345") | ||
logger.info("Starting order processing") | ||
finally: | ||
logger.info("Final state before clearing") | ||
logger.clear_state() | ||
logger.info("State after clearing - only show default keys") | ||
return "Completed" |
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