mirror of https://github.com/jumpserver/jumpserver
[bugfix] 解决日志中文报错以及各种utf8问题 (#2328)
parent
49a166552e
commit
4bf0dfcf7b
|
@ -209,19 +209,21 @@ LOGGING = {
|
||||||
'formatter': 'main'
|
'formatter': 'main'
|
||||||
},
|
},
|
||||||
'file': {
|
'file': {
|
||||||
|
'encoding': 'utf8',
|
||||||
'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
'class': 'logging.handlers.TimedRotatingFileHandler',
|
'class': 'logging.handlers.TimedRotatingFileHandler',
|
||||||
'when': "D",
|
'when': "D",
|
||||||
'interval': 1,
|
'interval': 1,
|
||||||
"backupCount": 7,
|
"backupCount": 7,
|
||||||
'formatter': 'main',
|
'formatter': 'main',
|
||||||
'filename': os.path.join(PROJECT_DIR, 'logs', 'jumpserver.log')
|
'filename': os.path.join(PROJECT_DIR, 'logs', 'jumpserver.log'),
|
||||||
},
|
},
|
||||||
'ansible_logs': {
|
'ansible_logs': {
|
||||||
|
'encoding': 'utf8',
|
||||||
'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
'class': 'logging.FileHandler',
|
'class': 'logging.FileHandler',
|
||||||
'formatter': 'main',
|
'formatter': 'main',
|
||||||
'filename': os.path.join(PROJECT_DIR, 'logs', 'ansible.log')
|
'filename': os.path.join(PROJECT_DIR, 'logs', 'ansible.log'),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'loggers': {
|
'loggers': {
|
||||||
|
|
|
@ -31,7 +31,7 @@ class CeleryTaskLogApi(generics.RetrieveAPIView):
|
||||||
if not log_path or not os.path.isfile(log_path):
|
if not log_path or not os.path.isfile(log_path):
|
||||||
return Response({"data": _("Waiting ...")}, status=203)
|
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)
|
offset = cache.get(mark, 0)
|
||||||
f.seek(offset)
|
f.seek(offset)
|
||||||
data = f.read(self.buff_size).replace('\n', '\r\n')
|
data = f.read(self.buff_size).replace('\n', '\r\n')
|
||||||
|
|
|
@ -81,7 +81,7 @@ def pre_run_task_signal_handler(sender, task_id=None, task=None, **kwargs):
|
||||||
t.status = CeleryTask.RUNNING
|
t.status = CeleryTask.RUNNING
|
||||||
t.log_path = log_path
|
t.log_path = log_path
|
||||||
t.save()
|
t.save()
|
||||||
f = open(full_path, 'w')
|
f = open(full_path, 'w', encoding="utf-8")
|
||||||
tee = TeeObj(f)
|
tee = TeeObj(f)
|
||||||
sys.stdout = tee
|
sys.stdout = tee
|
||||||
task.log_f = tee
|
task.log_f = tee
|
||||||
|
|
Loading…
Reference in New Issue