Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions core/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ def log(self, header, data):
self.end_sec()
self._log_flush()

def _rotate_log(self):
# copy the data in to a compressed file now
name = self._path + '-' + datetime.datetime.now().isoformat() + '.xz'

with open(self._path, "rb") as f:
with lzma.open(name, "w") as zf:
data = f.read()
while data:
zf.write(data)
data = f.read()

def _maybe_close(self):
if self._level:
return
Expand All @@ -90,21 +101,16 @@ def _maybe_close(self):
self._log_file.close()
self._log_file = None

# copy the data in to a compressed file now
name = self._path + '-' + datetime.datetime.now().isoformat() + '.xz'

with open(self._path, "rb") as f:
with lzma.open(name, "w") as zf:
data = f.read()
while data:
zf.write(data)
data = f.read()
self._rotate_log(self)

# truncate the main log by re-opening
self._log_file = open(self._path, "w+")
self._log_open()

def _log_open_init(self):
if os.path.isfile(self._path) and os.path.getsize(self._path) > 0:
self._rotate_log(self)

self._log_file = open(self._path, "w+")

def _log_open(self):
Expand Down
Loading