Skip to content

Commit

Permalink
Reopen event log on 'logreopen' or 'reopen_transcript' (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgedmin committed Apr 15, 2015
1 parent 0b95470 commit 560abe1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ Change log
- Make ``logreopen`` also reopen the transcript log:
https://github.com/zopefoundation/zdaemon/issues/9.

- Reopen event log on ``logreopen`` or ``reopen_transcript``:
https://github.com/zopefoundation/zdaemon/issues/8.

- Fix race condition where ``stop`` would be ignored if the daemon
manager was waiting before respawning a crashed program.
https://github.com/zopefoundation/zdaemon/issues/13.
Expand Down
45 changes: 44 additions & 1 deletion src/zdaemon/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
from __future__ import print_function

import doctest
import glob
import os
import re
import signal
import shutil
import signal
import subprocess
import sys
import tempfile
Expand Down Expand Up @@ -221,6 +222,48 @@ def test_logreopen():
"""


def test_log_rotation():
"""
>>> write('conf',
... '''
... <runner>
... program sleep 100
... transcript transcript.log
... </runner>
... <eventlog>
... <logfile>
... path event.log
... </logfile>
... </eventlog>
... ''')
>>> system("./zdaemon -Cconf start")
. .
daemon process started, pid=1234
Pretend we did a logrotate:
>>> os.rename('transcript.log', 'transcript.log.1')
>>> os.rename('event.log', 'event.log.1')
>>> system("./zdaemon -Cconf reopen_transcript") # or logreopen
This reopens both transcript.log and event.log:
>>> sorted(glob.glob('transcript.log*'))
['transcript.log', 'transcript.log.1']
>>> sorted(glob.glob('event.log*'))
['event.log', 'event.log.1']
>>> system("./zdaemon -Cconf stop")
. .
daemon process stopped
"""


def test_start_test_program():
"""
>>> write('t.py',
Expand Down
2 changes: 2 additions & 0 deletions src/zdaemon/zdrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
break

from zdaemon.zdoptions import RunnerOptions
from ZConfig.components.logger.loghandler import reopenFiles


def string_list(arg):
Expand Down Expand Up @@ -589,6 +590,7 @@ def cmd_status(self, args):
"args=%r\n" % self.proc.args)

def cmd_reopen_transcript(self, args):
reopenFiles()
if self.transcript is not None:
self.transcript.reopen()

Expand Down

0 comments on commit 560abe1

Please sign in to comment.