From 69d9bc65477ba3864183471dcdae15735bf0f4ea Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Tue, 23 Jun 2026 14:10:31 -0700 Subject: [PATCH 1/7] updates where logs are saved and catches complete with other post session functions --- src/foraging_gui/Foraging.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/foraging_gui/Foraging.py b/src/foraging_gui/Foraging.py index 3d377eccc..abd297d85 100644 --- a/src/foraging_gui/Foraging.py +++ b/src/foraging_gui/Foraging.py @@ -1990,11 +1990,7 @@ def _GetSettings(self): "aind_watchdog_service", "manifest", ), - "lifecycle_log_dir": os.path.join( - os.path.expanduser("~"), - "Documents", - "lifecycle_logs", - ), + "lifecycle_log_dir": os.path.join("C://Program Data//AllenInstitute//df_gui//logs"), "transfer_service_job_type": "dynamic_foraging_compression", "auto_engage": True, "clear_figure_after_save": True, @@ -4185,11 +4181,6 @@ def _Save(self, ForceSave=0, SaveAs=0, SaveContinue=0, BackupSave=0): elif session is None: logging.warning(f"Waterlog for mouse {self.behavior_session_model.subject} cannot be added to database" f" due do metadata generation failure.") - - # add complete log to lifecycle - self.lifecycle_logger.info("Session ended.", extra={"subject_id": self.behavior_session_model.subject, - "acquisition_name": self.behavior_session_model.session_name, - "event_type": "stage_complete"}) except Exception as e: logging.warning( @@ -6447,6 +6438,11 @@ def session_end_tasks(self): with open(self.behavior_session_modelJson, "w") as outfile: outfile.write(self.behavior_session_model.model_dump_json()) + # add complete log to lifecycle + self.lifecycle_logger.info("Session ended.", extra={"subject_id": self.behavior_session_model.subject, + "acquisition_name": self.behavior_session_model.session_name, + "event_type": "stage_complete"}) + def log_session(self) -> None: """ Setup a log handler to write logs during session to TrainingFolder From 7819bf4ab9c973589acd55110ae1a40e87a8f871 Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Tue, 23 Jun 2026 14:16:16 -0700 Subject: [PATCH 2/7] updates dir --- src/foraging_gui/Foraging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/foraging_gui/Foraging.py b/src/foraging_gui/Foraging.py index abd297d85..7cc7165b8 100644 --- a/src/foraging_gui/Foraging.py +++ b/src/foraging_gui/Foraging.py @@ -1990,7 +1990,7 @@ def _GetSettings(self): "aind_watchdog_service", "manifest", ), - "lifecycle_log_dir": os.path.join("C://Program Data//AllenInstitute//df_gui//logs"), + "lifecycle_log_dir": os.path.join("C://Program Data//AllenInstitute//dynamic-foraging-task//logs"), "transfer_service_job_type": "dynamic_foraging_compression", "auto_engage": True, "clear_figure_after_save": True, From 0f975ba8d4dabd40b7cf2534a2a607de0fbc7904 Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Wed, 24 Jun 2026 11:40:47 -0700 Subject: [PATCH 3/7] disable log propogation --- src/foraging_gui/Foraging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/foraging_gui/Foraging.py b/src/foraging_gui/Foraging.py index 7cc7165b8..19d4b18c3 100644 --- a/src/foraging_gui/Foraging.py +++ b/src/foraging_gui/Foraging.py @@ -377,7 +377,7 @@ def setup_lifecycle_logger(self) -> logging.Logger: lifecycle_logger = logging.getLogger("lifecycle") lifecycle_logger.setLevel(logging.INFO) - + lifecycle_logger.propagate = False timestamp = datetime.now().strftime("%Y%m%dT%H%M%SZ") filename = f"lifecycle_log_{timestamp}.jsonl" file_handler = logging.FileHandler(os.path.join(self.Settings["lifecycle_log_dir"], filename), encoding="utf-8") From 56c0926d65c0f98c1e1e5aa308b1b46d2b51c69c Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Wed, 24 Jun 2026 12:12:56 -0700 Subject: [PATCH 4/7] removes file logger from root --- src/foraging_gui/Foraging.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/foraging_gui/Foraging.py b/src/foraging_gui/Foraging.py index 19d4b18c3..5a2e8b2ad 100644 --- a/src/foraging_gui/Foraging.py +++ b/src/foraging_gui/Foraging.py @@ -377,7 +377,7 @@ def setup_lifecycle_logger(self) -> logging.Logger: lifecycle_logger = logging.getLogger("lifecycle") lifecycle_logger.setLevel(logging.INFO) - lifecycle_logger.propagate = False + timestamp = datetime.now().strftime("%Y%m%dT%H%M%SZ") filename = f"lifecycle_log_{timestamp}.jsonl" file_handler = logging.FileHandler(os.path.join(self.Settings["lifecycle_log_dir"], filename), encoding="utf-8") @@ -7439,7 +7439,9 @@ def start_gui_log_file(box_number): file_handler = logging.FileHandler(logging_filename) file_handler.setFormatter(log_formatter) file_handler.setLevel(logging.INFO) - logger.root.addHandler(file_handler) + logger = logging.getLogger(__name__) + logger.addHandler(file_handler) + logger.setLevel(logging.INFO) logging.info("Starting logfile!") logging.captureWarnings(True) From b716e2e42d902f0f7486bdf7f4c751ae9cd68376 Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Wed, 24 Jun 2026 12:18:59 -0700 Subject: [PATCH 5/7] reconfigures root logger --- src/foraging_gui/Foraging.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/foraging_gui/Foraging.py b/src/foraging_gui/Foraging.py index 5a2e8b2ad..924ceef67 100644 --- a/src/foraging_gui/Foraging.py +++ b/src/foraging_gui/Foraging.py @@ -353,6 +353,14 @@ def __init__(self, parent=None, box_number=1, start_bonsai_ide=True): # setup life-cycle logger self.lifecycle_logger = self.setup_lifecycle_logger() + # reconfigure root logger + root_logger = logging.getLogger(__name__) + log_format = "%(asctime)s:%(levelname)s:%(module)s:%(filename)s:%(funcName)s:line %(lineno)d:%(message)s" + log_datefmt = "%I:%M:%S %p" + correct_formatter = logging.Formatter(fmt=log_format, datefmt=log_datefmt) + for handler in root_logger.handlers: + handler.setFormatter(correct_formatter) + # Initializes session log handler as None self.session_log_handler = None From cfc4535649e31ef3ca8fdf150919ecbe756971a6 Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Wed, 24 Jun 2026 12:21:23 -0700 Subject: [PATCH 6/7] adds log file back to root logger --- src/foraging_gui/Foraging.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/foraging_gui/Foraging.py b/src/foraging_gui/Foraging.py index 924ceef67..061b510b7 100644 --- a/src/foraging_gui/Foraging.py +++ b/src/foraging_gui/Foraging.py @@ -7447,9 +7447,7 @@ def start_gui_log_file(box_number): file_handler = logging.FileHandler(logging_filename) file_handler.setFormatter(log_formatter) file_handler.setLevel(logging.INFO) - logger = logging.getLogger(__name__) - logger.addHandler(file_handler) - logger.setLevel(logging.INFO) + logger.root.addHandler(file_handler) logging.info("Starting logfile!") logging.captureWarnings(True) From 83f5a7dd113b62bbd74f6bfe3e0a3b5f145e1d22 Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Wed, 24 Jun 2026 12:39:11 -0700 Subject: [PATCH 7/7] set basic config level to info --- src/foraging_gui/Foraging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/foraging_gui/Foraging.py b/src/foraging_gui/Foraging.py index 061b510b7..88a63f3b6 100644 --- a/src/foraging_gui/Foraging.py +++ b/src/foraging_gui/Foraging.py @@ -95,7 +95,7 @@ logger = logging.getLogger(__name__) logger.root.handlers.clear() # clear handlers so console output can be configured logging.raiseExceptions = os.getenv("FORAGING_DEV_MODE", False) - +logging.basicConfig(level=logging.INFO) class NumpyEncoder(json.JSONEncoder): def default(self, obj):