From 81974f66ec3eb8cabc5b7484476e42a68e3bc629 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 8 Jan 2021 14:45:08 +0000 Subject: [PATCH] monitor/dashboard: move away from `if __debug__` This includes changing one print_exc() to logger.exception() --- dashboard.py | 21 ++++++++++----------- monitor.py | 3 +-- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/dashboard.py b/dashboard.py index 43ac67a7..4e7f9ce6 100644 --- a/dashboard.py +++ b/dashboard.py @@ -1,16 +1,13 @@ import json from calendar import timegm -from operator import itemgetter -from os import listdir from os.path import isdir, isfile, join, getsize from sys import platform import time -if __debug__: - from traceback import print_exc - from config import config +from EDMCLogging import get_main_logger +logger = get_main_logger() if platform=='darwin': from watchdog.observers import Observer @@ -67,8 +64,10 @@ class Dashboard(FileSystemEventHandler): if not self.observed and not polling: self.observed = self.observer.schedule(self, self.currentdir) - if __debug__: - print('%s Dashboard "%s"' % (polling and 'Polling' or 'Monitoring', self.currentdir)) + if polling: + logger.debug(f'Polling Dashboard "{self.currentdir}"') + else: + logger.debug(f'Monitoring Dashboard "{self.currentdir}"') # Even if we're not intending to poll, poll at least once to process pre-existing # data and to check whether the watchdog thread has crashed due to events not @@ -78,8 +77,8 @@ class Dashboard(FileSystemEventHandler): return True def stop(self): - if __debug__: - print('Stopping monitoring Dashboard') + logger.debug('Stopping monitoring Dashboard') + self.currentdir = None if self.observed: self.observed = None @@ -127,8 +126,8 @@ class Dashboard(FileSystemEventHandler): self.status != entry): self.status = entry self.root.event_generate('<>', when="tail") - except: - if __debug__: print_exc() + except Exception: + logger.exception('Reading Status.json') # singleton dashboard = Dashboard() diff --git a/monitor.py b/monitor.py index 792d2a77..9b57ef2d 100644 --- a/monitor.py +++ b/monitor.py @@ -187,8 +187,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below return True def stop(self): - if __debug__: - print('Stopping monitoring Journal') + logger.debug('Stopping monitoring Journal') self.currentdir = None self.version = None