syncevolution/test/logger.py
Patrick Ohly f3e1e10916 wrappercheck: augment output of daemon with time stamps
Useful for correlating events in the daemon with events in testing.
We need to use a process group to deliver SIGINT/SIGTERM, otherwise
we cannot be sure that we catch all processes created by the daemon.

The return code of the daemon was not checked before (accidentally?!)
and this patch does not change that. Might be fixed in the future.
2014-10-24 07:13:33 -07:00

45 lines
1.4 KiB
Python
Executable file

#! /usr/bin/python
#
# Copyright (C) 2014 Intel Corporation
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) version 3.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# Augments stdin by adding a "log starting" preamble and "log ending"
# footer and a time stamp to each line. Flushes after each line
# and ignores SIGTERM and SIGINT, in order to not loose unprocessed
# output.
import os
import re
import signal
import sys
import time
def now():
return time.strftime('%H:%M:%S', time.gmtime())
signal.signal(signal.SIGTERM, lambda x,y: sys.stdout.write('--- SIGTERM at %s ---\n' % now()))
signal.signal(signal.SIGINT, lambda x,y: sys.stdout.write('--- SIGINT at %s ---\n' % now()))
sys.stdout.write('--- log starting at %s ---\n' % now())
sys.stdout.flush()
while True:
line = sys.stdin.readline()
if not line:
break
if not line[0].isspace():
sys.stdout.write(now() + ' ')
sys.stdout.write(line)
sys.stdout.flush()
sys.stdout.write('--- log ending at %s ---\n' % now())
sys.stdout.flush()