Skip to content

Commit

Permalink
fix: fix logging in run_tests #10
Browse files Browse the repository at this point in the history
  • Loading branch information
furkan-bilgin committed Nov 14, 2024
1 parent b1e3e2e commit 9bab512
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ class Supervisor:
daq_job_threads: list[DAQJobThread]
daq_job_stats: DAQJobStatsDict
restart_schedules: list[RestartDAQJobSchedule]
_logger: logging.Logger

def init(self):
self._logger = logging.getLogger(f"Supervisor({self.config.supervisor_id})")
self.config = self._load_supervisor_config()
# Change logging name based on supervisor id
logging.getLogger().name = f"Supervisor({self.config.supervisor_id})"

self.restart_schedules = []
self.daq_job_threads = self.start_daq_job_threads()
Expand All @@ -58,7 +59,7 @@ def run(self):
self.loop()
time.sleep(DAQ_SUPERVISOR_SLEEP_TIME_SECONDS)
except KeyboardInterrupt:
logging.warning("KeyboardInterrupt received, cleaning up")
self._logger.warning("KeyboardInterrupt received, cleaning up")
for daq_job_thread in self.daq_job_threads:
daq_job_thread.daq_job.__del__()
break
Expand Down Expand Up @@ -93,7 +94,7 @@ def get_restart_schedules(self, dead_threads: list[DAQJobThread]):
if not isinstance(restart_offset, timedelta):
restart_offset = timedelta(seconds=0)
else:
logging.info(
self._logger.info(
f"Scheduling restart of {type(thread.daq_job).__name__} in {restart_offset.total_seconds()} seconds"
)
res.append(
Expand Down Expand Up @@ -194,11 +195,11 @@ def warn_for_lack_of_daq_jobs(self):
if not any(
x for x in self.daq_job_threads if isinstance(x.daq_job, daq_job_type)
):
logging.warning(warning_message)
self._logger.warning(warning_message)

def _load_supervisor_config(self):
if not os.path.exists(SUPERVISOR_CONFIG_FILE_PATH):
logging.warning(
self._logger.warning(
f"No supervisor config file found at '{SUPERVISOR_CONFIG_FILE_PATH}', using default config"
)
return SupervisorConfig(supervisor_id=platform.node())
Expand Down

0 comments on commit 9bab512

Please sign in to comment.