5 import select, signal, time, errno
10 sys.stderr.write(
"m: " + s +
"\n");
18 self.
zstream = zlib.compressobj(6, zlib.DEFLATED, zlib.MAX_WBITS | 16)
26 self.
file = open(log_file,
"wb+")
53 self.
zstream.flush(zlib.Z_FINISH)
59 self.
write_block(
"\n\n--- file was cut at this point ---\n\n")
80 if timeout
or large_block:
95 log_handler =
GZipLog(log_file=args.log)
97 def sigusr1_handle(*kargs, **kwargs):
98 log_handler._sigusr_interrupt =
True
100 log_handler.flush_block()
102 signal.signal(signal.SIGUSR1, sigusr1_handle)
107 log_handler._sigusr_interrupt =
False
108 rlist, wlist, xlist = select.select([fd], [], [], 5)
109 except select.error
as e:
110 if e[0] != errno.EINTR:
raise
111 if not log_handler._sigusr_interrupt:
raise
116 log_handler.handle_timeout()
119 bytes = os.read(fd, 4096)
123 log_handler.write(bytes)
125 sys.stdout.write(bytes)
129 if __name__ ==
"__main__":
130 parser = argparse.ArgumentParser(description=
"Take all input and write a compressed log file.")
131 parser.add_argument(
'-q', action=
'store_true', help=
"Don't write to stdout, just the log file.")
132 parser.add_argument(
"log", type=str, help=
"Filename to write.", metavar=
"<logfile.gz>")
133 args = parser.parse_args()
136 fd = sys.stdout.fileno()
140 capture(sys.stdin.fileno(), args)