From 82cfa6452775aa01ea74bd31ff2421cf66ebf0fb Mon Sep 17 00:00:00 2001 From: petrucci4prez Date: Mon, 29 May 2017 21:53:08 -0400 Subject: [PATCH] add some clarifying remarks --- notifier.py | 1 + sharedLogging.py | 16 +++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/notifier.py b/notifier.py index 61a47ef..1600900 100644 --- a/notifier.py +++ b/notifier.py @@ -29,6 +29,7 @@ def scheduleAction(action): time.sleep(sleepTime.days * 86400 + sleepTime.seconds) action() +# probably an easier way to do this in logging module @async(daemon=False) def sendEmail(subject, body): msg = MIMEMultipart() diff --git a/sharedLogging.py b/sharedLogging.py index 98c2212..2392cd6 100644 --- a/sharedLogging.py +++ b/sharedLogging.py @@ -3,13 +3,14 @@ from subprocess import run, PIPE, CalledProcessError from logging.handlers import TimedRotatingFileHandler # formats console output depending on whether we have gluster -def _formatConsole(rotatingFile=False): - c = '' if rotatingFile else '[CONSOLE ONLY] ' +def _formatConsole(gluster = False): + c = '' if gluster else '[CONSOLE ONLY] ' fmt = logging.Formatter('[%(name)s] [%(levelname)s] ' + c + '%(message)s') console.setFormatter(fmt) +# init console, but don't expect gluster to be here yet console = logging.StreamHandler() -_formatConsole(False) +_formatConsole(gluster = False) rootLogger = logging.getLogger() rootLogger.setLevel(logging.DEBUG) @@ -70,7 +71,8 @@ class GlusterFSHandler(TimedRotatingFileHandler): def close(self): TimedRotatingFileHandler.close(self) # must close file stream before unmounting self._unmount() - + +# ...now activate gluster gluster = GlusterFSHandler( server = '192.168.11.39', volume = 'pyledriver', @@ -78,10 +80,10 @@ gluster = GlusterFSHandler( options = 'backupvolfile-server=192.168.11.48' ) -_formatConsole(True) +_formatConsole(gluster = True) rootLogger.addHandler(gluster) +# this should only be called at the end to clean up def unmountGluster(): rootLogger.removeHandler(gluster) - _formatConsole(False) - + _formatConsole(gluster = False)