From 4bf0dfcf7b541edb01da32f7e32965516fd79ddd Mon Sep 17 00:00:00 2001 From: xiaomao Date: Tue, 8 Jan 2019 15:27:15 +0800 Subject: [PATCH] =?UTF-8?q?[bugfix]=20=E8=A7=A3=E5=86=B3=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E4=B8=AD=E6=96=87=E6=8A=A5=E9=94=99=E4=BB=A5=E5=8F=8A=E5=90=84?= =?UTF-8?q?=E7=A7=8Dutf8=E9=97=AE=E9=A2=98=20(#2328)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/jumpserver/settings.py | 6 ++++-- apps/ops/api/celery.py | 2 +- apps/ops/celery/signal_handler.py | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/jumpserver/settings.py b/apps/jumpserver/settings.py index 2a0f44f96..db1822839 100644 --- a/apps/jumpserver/settings.py +++ b/apps/jumpserver/settings.py @@ -209,19 +209,21 @@ LOGGING = { 'formatter': 'main' }, 'file': { + 'encoding': 'utf8', 'level': 'DEBUG', 'class': 'logging.handlers.TimedRotatingFileHandler', 'when': "D", 'interval': 1, "backupCount": 7, 'formatter': 'main', - 'filename': os.path.join(PROJECT_DIR, 'logs', 'jumpserver.log') + 'filename': os.path.join(PROJECT_DIR, 'logs', 'jumpserver.log'), }, 'ansible_logs': { + 'encoding': 'utf8', 'level': 'DEBUG', 'class': 'logging.FileHandler', 'formatter': 'main', - 'filename': os.path.join(PROJECT_DIR, 'logs', 'ansible.log') + 'filename': os.path.join(PROJECT_DIR, 'logs', 'ansible.log'), }, }, 'loggers': { diff --git a/apps/ops/api/celery.py b/apps/ops/api/celery.py index 2640cffec..ae8f479d6 100644 --- a/apps/ops/api/celery.py +++ b/apps/ops/api/celery.py @@ -31,7 +31,7 @@ class CeleryTaskLogApi(generics.RetrieveAPIView): if not log_path or not os.path.isfile(log_path): return Response({"data": _("Waiting ...")}, status=203) - with open(log_path, 'r') as f: + with open(log_path, 'r', encoding="utf8") as f: offset = cache.get(mark, 0) f.seek(offset) data = f.read(self.buff_size).replace('\n', '\r\n') diff --git a/apps/ops/celery/signal_handler.py b/apps/ops/celery/signal_handler.py index 961c18ad3..ae7acc2ea 100644 --- a/apps/ops/celery/signal_handler.py +++ b/apps/ops/celery/signal_handler.py @@ -81,7 +81,7 @@ def pre_run_task_signal_handler(sender, task_id=None, task=None, **kwargs): t.status = CeleryTask.RUNNING t.log_path = log_path t.save() - f = open(full_path, 'w') + f = open(full_path, 'w', encoding="utf-8") tee = TeeObj(f) sys.stdout = tee task.log_f = tee