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+")
34 self.file.write(self.zstream.compress(data))
35 self.file.write(self.zstream.flush(zlib.Z_FULL_FLUSH))
53 self.zstream.flush(zlib.Z_FINISH)
57 self.
zstream = self.file_truncate_state.copy()
59 self.
write_block(
"\n\n--- file was cut at this point ---\n\n")
72 self.file.write(self.zstream.flush(zlib.Z_FINISH))
80 if timeout
or large_block:
85 self.block.append(bytes)
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)
static std::string join(char **cmd)
def write_block(self, data)
def __init__(self, log_file)