Skip to content

Commit

Permalink
Merge pull request #1323 from knutfrode/dev
Browse files Browse the repository at this point in the history
OpenDriftGUI now logs to file in addition to GUI window
  • Loading branch information
knutfrode authored Jun 20, 2024
2 parents 5577ceb + 1321313 commit 572f1ba
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions opendrift/scripts/opendrift_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,11 +722,6 @@ def check_seeding(self):
def run_opendrift(self):
sys.stdout.write('running OpenDrift')

# Creating fresh instance of the current model, but keeping config
adjusted_config = self.o._config
self.set_model(self.modelname, rebuild_gui=False)
self.o._config = adjusted_config

try:
self.budgetbutton.destroy()
except Exception as e:
Expand All @@ -752,6 +747,23 @@ def run_opendrift(self):
start_time = local_start.astimezone(pytz.utc).replace(tzinfo=None)
end_time = local_end.astimezone(pytz.utc).replace(tzinfo=None)

# Creating fresh instance of the current model, but keeping config
adjusted_config = self.o._config
self.set_model(self.modelname, rebuild_gui=False)
self.o._config = adjusted_config

# Add secondary log-handler to file
if self.has_diana is True and True:
logfile = self.outputdir + '/opendrift_' + self.modelname + start_time.strftime('_%Y%m%d_%H%M.log')
import logging
if hasattr(self, 'handler'):
logging.getLogger('opendrift').removeHandler(self.handler)
self.handler = logging.FileHandler(logfile, mode='w')
self.handler.setFormatter(logging.getLogger('opendrift').handlers[0].formatter)
logging.getLogger('opendrift').addHandler(self.handler)
if len(logging.getLogger('opendrift').handlers) > 2:
raise ValueError('Too many log handlers')

sys.stdout.flush()
lon = float(self.lon.get())
lat = float(self.lat.get())
Expand Down

0 comments on commit 572f1ba

Please sign in to comment.