From cb15250efd65984afcf1fe1dc345ad839526e0ab Mon Sep 17 00:00:00 2001 From: petrucci4prez Date: Tue, 23 May 2017 01:36:25 -0400 Subject: [PATCH] check log destination dir --- sharedLogging.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sharedLogging.py b/sharedLogging.py index 20a9ea8..413c523 100644 --- a/sharedLogging.py +++ b/sharedLogging.py @@ -58,8 +58,15 @@ class MasterLogger(): console = logging.StreamHandler() console.setFormatter(consoleFormat) - # TODO: check that 'logs' actually exists in the mp - self.rotatingFile = TimedRotatingFileHandler(mountpoint + '/logs/pyledriver-log', when='midnight') + logdest = mountpoint + '/logs' + + if not os.path.exists(logdest): + os.mkdir(logdest) + elif os.path.isfile(logdest): + fallbackLogger(__name__, 'CRITICAL', '{} is present but is a file (vs a directory). Please (re)move this file to prevent data loss'.format(logdest)) + sys.exit() + + self.rotatingFile = TimedRotatingFileHandler(logdest + '/pyledriver-log', when='midnight') self.rotatingFile.setFormatter(fileFormat) logging.basicConfig(level=getattr(logging, level), handlers=[QueueHandler(queue)])