@@ -1146,6 +1146,28 @@ def test_log_error_invokeId_line_framed_log_sink(self):
11461146 actual_message = content [16 :].decode ()
11471147 self .assertEqual (actual_message , expected_logged_error )
11481148
1149+ @patch ("sys.stdout" , new_callable = StringIO )
1150+ def test_log_error_json_log_sink_uses_level_key (self , mock_stdout ):
1151+ with patch .dict (os .environ , {"AWS_LAMBDA_LOG_FORMAT" : "JSON" }, clear = True ):
1152+ importlib .reload (bootstrap )
1153+ self .addCleanup (self ._reload_default_bootstrap )
1154+
1155+ err_to_log = bootstrap .make_error (
1156+ "Error message" , "ErrorType" , ["line1" , "line2" ]
1157+ )
1158+ bootstrap .log_error (err_to_log , bootstrap .StandardLogSink ())
1159+
1160+ logged = json .loads (mock_stdout .getvalue ())
1161+ self .assertEqual (logged ["level" ], "ERROR" )
1162+ self .assertNotIn ("log_level" , logged )
1163+ self .assertEqual (logged ["errorType" ], "ErrorType" )
1164+ self .assertEqual (logged ["errorMessage" ], "Error message" )
1165+
1166+ @staticmethod
1167+ def _reload_default_bootstrap ():
1168+ with patch .dict (os .environ , {}, clear = True ):
1169+ importlib .reload (bootstrap )
1170+
11491171
11501172class TestUnbuffered (unittest .TestCase ):
11511173 def test_write (self ):
0 commit comments