logging, throw an exception when logfile doesn't look like a clog file, makes it easier to auto-detect clog/plain logs

This commit is contained in:
Ad Schellevis 2019-11-26 21:44:46 +01:00
parent 8df5374a9f
commit 5c6d780f8c

View File

@ -85,6 +85,8 @@ def fetch_clog(input_log):
mm = mmap.mmap(fd.fileno(), 0)
# unpack clog information struct
clog_footer = struct.unpack('iiii', mm[-16:]) # cf_magic, cf_wrap, cf_next, cf_max, cf_lock
if mm[-20:-16] != b'CLOG':
raise Exception('not a valid clog file')
# concat log file into new output stream, start at current wrap position
output_stream = StringIO(mm[clog_footer[1]:-20].decode() + mm[:clog_footer[1]].decode())
output_stream.seek(0)