Renames Old Log File if It Exists

This commit is contained in:
2023-04-28 03:55:07 -03:00
parent 5666eb8c28
commit 56994dba27
3 changed files with 23 additions and 6 deletions

View File

@@ -1,3 +1,4 @@
from pathlib import Path
import logging
@@ -24,7 +25,9 @@ class Logger:
self._logger = logging.getLogger(logger_name)
def set_logger(self, outfile='run.log', level=logging.INFO):
self.outfile = outfile
self.outfile = Path(outfile)
if self.outfile.exists():
self.outfile.rename(str(self.outfile) + ".backup")
if level is not None:
self._logger.setLevel(level)