Skip to content

Commit edbc073

Browse files
committed
Simplify InversionLogger
1 parent f500893 commit edbc073

1 file changed

Lines changed: 6 additions & 16 deletions

File tree

simpeg_drivers/driver.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,10 @@ def from_input_file(cls, data: dict) -> type[InversionDriver]:
895895
class InversionLogger:
896896
"""
897897
Logger for the inversion process.
898+
899+
Writes messages to both the terminal and a log file in the same directory as the workspace.
900+
901+
:param driver: The inversion driver to log for.
898902
"""
899903

900904
def __init__(self, driver):
@@ -906,36 +910,22 @@ def __init__(self, driver):
906910
self.logfile = self.get_path(f"SimPEG_{self.start_date_time}.log")
907911

908912
def start(self):
909-
910913
self.write(
911914
f"Running simpeg-drivers {__version__}\n"
912915
f"Started {self.start_date_time}\n"
913916
f"{self.driver.params.title}\n"
914917
)
915918

916919
def end(self):
917-
elapsed_time = timedelta(seconds=time() - self.initial_time).seconds
918-
days, hours, minutes, seconds = self.format_seconds(elapsed_time)
919-
self.write(
920-
f"Total runtime: {days} days, {hours} hours, {minutes} minutes, and {seconds} seconds.\n"
921-
)
920+
elapsed_time = timedelta(seconds=time() - self.initial_time)
921+
self.write(f"Total runtime: {elapsed_time}\n")
922922

923923
def write(self, message):
924924
self.terminal.write(message)
925925
with open(self.logfile, "a", encoding="utf8") as logfile:
926926
logfile.write(message)
927927
logfile.flush()
928928

929-
@staticmethod
930-
def format_seconds(seconds):
931-
days = seconds // (24 * 3600)
932-
seconds = seconds % (24 * 3600)
933-
hours = seconds // 3600
934-
seconds = seconds % 3600
935-
minutes = seconds // 60
936-
seconds = seconds % 60
937-
return days, hours, minutes, seconds
938-
939929
def close(self):
940930
self.terminal.close()
941931

0 commit comments

Comments
 (0)