@@ -683,6 +683,29 @@ def handler(event, context):
683
683
assert key in second_log
684
684
685
685
686
+ def test_clear_state_keeps_custom_keys (lambda_context , stdout , service_name ):
687
+ # GIVEN
688
+ date_format = "%Y"
689
+ location_format = "%(module)s:%(funcName)s:%(lineno)d"
690
+ logger = Logger (service = service_name , stream = stdout , location = location_format , datefmt = date_format )
691
+
692
+ # WHEN clear_state is set
693
+ @logger .inject_lambda_context (clear_state = True )
694
+ def handler (event , context ):
695
+ logger .info ("Foo" )
696
+
697
+ # THEN all standard keys should be available as usual
698
+ handler ({}, lambda_context )
699
+ handler ({}, lambda_context )
700
+
701
+ first_log , second_log = capture_multiple_logging_statements_output (stdout )
702
+
703
+ assert re .fullmatch ("[0-9]{4}" , first_log ["timestamp" ])
704
+ assert re .fullmatch ("[0-9]{4}" , second_log ["timestamp" ])
705
+ assert re .fullmatch (".+:.+:[0-9]+" , first_log ["location" ])
706
+ assert re .fullmatch (".+:.+:[0-9]+" , second_log ["location" ])
707
+
708
+
686
709
def test_clear_state_keeps_exception_keys (lambda_context , stdout , service_name ):
687
710
# GIVEN
688
711
logger = Logger (service = service_name , stream = stdout )
0 commit comments