File tree 2 files changed +21
-0
lines changed
aws_lambda_powertools/logging
2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -133,6 +133,7 @@ def __init__(
133
133
default = self .json_default ,
134
134
separators = ("," , ":" ),
135
135
indent = self .json_indent ,
136
+ ensure_ascii = False , # see #3474
136
137
)
137
138
138
139
self .datefmt = datefmt
Original file line number Diff line number Diff line change @@ -1120,3 +1120,23 @@ def filter(self, record):
1120
1120
log = capture_multiple_logging_statements_output (stdout )
1121
1121
assert log [0 ]["api_key" ] == "REDACTED"
1122
1122
assert log [1 ]["api_key" ] != "REDACTED"
1123
+
1124
+
1125
+ def test_logger_json_unicode (stdout , service_name ):
1126
+ # GIVEN Logger is initialized
1127
+ logger = Logger (service = service_name , stream = stdout )
1128
+
1129
+ # WHEN all non-ascii chars are logged as messages
1130
+ # AND non-ascii is also used as ephemeral fields
1131
+ # latest: https://www.unicode.org/versions/Unicode15.1.0/#Summary
1132
+ non_ascii_chars = [chr (i ) for i in range (128 , 111_411_1 )]
1133
+ japanese_field = "47業レルし化"
1134
+ japanese_string = "スコビルデモ2"
1135
+
1136
+ logger .info (non_ascii_chars , ** {japanese_field : japanese_string })
1137
+
1138
+ # THEN JSON logs should not try to escape them
1139
+ log = capture_logging_output (stdout )
1140
+
1141
+ assert log ["message" ] == non_ascii_chars
1142
+ assert log [japanese_field ] == japanese_string
You can’t perform that action at this time.
0 commit comments