Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
4bf0dfcf
Commit
4bf0dfcf
authored
Jan 08, 2019
by
xiaomao
Committed by
老广
Jan 08, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[bugfix] 解决日志中文报错以及各种utf8问题 (#2328)
parent
49a16655
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
4 deletions
+6
-4
settings.py
apps/jumpserver/settings.py
+4
-2
celery.py
apps/ops/api/celery.py
+1
-1
signal_handler.py
apps/ops/celery/signal_handler.py
+1
-1
No files found.
apps/jumpserver/settings.py
View file @
4bf0dfcf
...
...
@@ -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'
:
{
...
...
apps/ops/api/celery.py
View file @
4bf0dfcf
...
...
@@ -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
'
)
...
...
apps/ops/celery/signal_handler.py
View file @
4bf0dfcf
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment