From e8c8e30fc4f618273dec1415c752eed203c75b67 Mon Sep 17 00:00:00 2001 From: ArthurYueh Date: Tue, 16 Mar 2021 00:33:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Add=20json=20setting=20to=20allow=20uni?= =?UTF-8?q?codes=20to=20show=20in=20log=20instead=20of=20ascii=20ch?= =?UTF-8?q?=E2=80=A6=20(#193)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- google/cloud/logging_v2/handlers/_helpers.py | 2 +- tests/unit/handlers/test_container_engine.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/google/cloud/logging_v2/handlers/_helpers.py b/google/cloud/logging_v2/handlers/_helpers.py index fff1e9a8..88eba07a 100644 --- a/google/cloud/logging_v2/handlers/_helpers.py +++ b/google/cloud/logging_v2/handlers/_helpers.py @@ -48,7 +48,7 @@ def format_stackdriver_json(record, message): "severity": record.levelname, } - return json.dumps(payload) + return json.dumps(payload, ensure_ascii=False) def get_request_data_from_flask(): diff --git a/tests/unit/handlers/test_container_engine.py b/tests/unit/handlers/test_container_engine.py index d2ae8388..280ab9cf 100644 --- a/tests/unit/handlers/test_container_engine.py +++ b/tests/unit/handlers/test_container_engine.py @@ -40,7 +40,7 @@ def test_format(self): handler = self._make_one() logname = "loggername" - message = "hello world" + message = "hello world,嗨 世界" record = logging.LogRecord( logname, logging.INFO, None, None, message, None, None ) @@ -53,4 +53,4 @@ def test_format(self): } payload = handler.format(record) - self.assertEqual(payload, json.dumps(expected_payload)) + self.assertEqual(payload, json.dumps(expected_payload, ensure_ascii=False))