Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mitogen
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
mitogen
Commits
a06c92d2
Commit
a06c92d2
authored
Mar 17, 2018
by
David Wilson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: enable_debug_logging() should reopen file post-fork.
parent
051fb85d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
5 deletions
+26
-5
mitogen/core.py
mitogen/core.py
+26
-5
No files found.
mitogen/core.py
View file @
a06c92d2
...
...
@@ -212,15 +212,36 @@ def io_op(func, *args):
return
None
,
True
class
PidfulStreamHandler
(
logging
.
StreamHandler
):
open_pid
=
None
template
=
'/tmp/mitogen.%s.%s.log'
def
_reopen
(
self
):
self
.
acquire
()
try
:
ts
=
time
.
strftime
(
'%Y%m%d_%H%M%S'
)
path
=
self
.
template
%
(
os
.
getpid
(),
ts
)
self
.
stream
=
open
(
path
,
'w'
,
1
)
set_cloexec
(
self
.
stream
.
fileno
())
self
.
stream
.
write
(
'Parent PID: %s
\
n
'
%
(
os
.
getppid
(),))
self
.
stream
.
write
(
'Created by:
\
n
\
n
%s
\
n
'
%
(
''
.
join
(
traceback
.
format_stack
()),
))
self
.
open_pid
=
os
.
getpid
()
finally
:
self
.
release
()
def
emit
(
self
,
record
):
if
self
.
open_pid
!=
os
.
getpid
():
self
.
_reopen
()
return
super
(
PidfulStreamHandler
,
self
).
emit
(
record
)
def
enable_debug_logging
():
root
=
logging
.
getLogger
()
root
.
setLevel
(
logging
.
DEBUG
)
IOLOG
.
setLevel
(
logging
.
DEBUG
)
fp
=
open
(
'/tmp/mitogen.%s.log'
%
(
os
.
getpid
(),),
'w'
,
1
)
fp
.
write
(
'Parent PID: %s
\
n
'
%
(
os
.
getppid
(),))
fp
.
write
(
'Created by:
\
n
\
n
%s
\
n
\
n
'
%
(
''
.
join
(
traceback
.
format_stack
()),))
set_cloexec
(
fp
.
fileno
())
handler
=
logging
.
StreamHandler
(
fp
)
handler
=
PidfulStreamHandler
()
handler
.
formatter
=
logging
.
Formatter
(
'%(asctime)s %(levelname).1s %(name)s: %(message)s'
,
'%H:%M:%S'
...
...
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