Skip to content
Snippets Groups Projects
Commit 80e1d9b3 authored by lukas leufen's avatar lukas leufen
Browse files

Merge branch 'lukas_issue085_refac_log-file-counter' into 'develop'

Resolve "logging with counter"

See merge request toar/machinelearningtools!83
parents 1dbd0841 9bc43bf7
Branches
Tags
3 merge requests!90WIP: new release update,!89Resolve "release branch / CI on gpu",!83Resolve "logging with counter"
Pipeline #32766 passed
...@@ -39,11 +39,7 @@ class RunEnvironment(object): ...@@ -39,11 +39,7 @@ class RunEnvironment(object):
logging.info(f"{self.__class__.__name__} finished after {self.time}") logging.info(f"{self.__class__.__name__} finished after {self.time}")
self.del_by_exit = True self.del_by_exit = True
if self.__class__.__name__ == "RunEnvironment": if self.__class__.__name__ == "RunEnvironment":
try: self.__copy_log_file()
new_file = os.path.join(self.data_store.get("experiment_path"), "logging.log")
shutil.copyfile(self.logger.log_file, new_file)
except (NameNotFoundInDataStore, FileNotFoundError):
pass
self.data_store.clear_data_store() self.data_store.clear_data_store()
def __enter__(self): def __enter__(self):
...@@ -54,6 +50,20 @@ class RunEnvironment(object): ...@@ -54,6 +50,20 @@ class RunEnvironment(object):
logging.error(exc_val, exc_info=(exc_type, exc_val, exc_tb)) logging.error(exc_val, exc_info=(exc_type, exc_val, exc_tb))
self.__del__() self.__del__()
def __copy_log_file(self):
try:
counter = 0
filename_pattern = os.path.join(self.data_store.get("experiment_path"), "logging_%03i.log")
new_file = filename_pattern % counter
while os.path.exists(new_file):
counter += 1
new_file = filename_pattern % counter
logging.info(f"Copy log file to {new_file}")
shutil.copyfile(self.logger.log_file, new_file)
except (NameNotFoundInDataStore, FileNotFoundError):
pass
@staticmethod @staticmethod
def do_stuff(length=2): def do_stuff(length=2):
time.sleep(length) time.sleep(length)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment