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

@@ -50,10 +50,6 @@ def main():
with open(pickle_path) as pickle_file:
save = pickle.load(pickle_file)
output_path = Path(args.outfile)
if output_path.exists():
output_path.rename(str(output_path) + ".backup")
except Exception as err:
sys.exit(err)

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)