clean up logging

This commit is contained in:
petrucci4prez 2017-05-30 02:11:15 -04:00
parent fc6d6c4cc9
commit af32fc6d26
6 changed files with 33 additions and 22 deletions

View File

@ -50,12 +50,14 @@ class CountdownTimer(Thread):
def __del__(self): def __del__(self):
self.stop() self.stop()
def waitForPath(path, timeout=30): def waitForPath(path, logger=None, timeout=30):
for i in range(0, timeout): for i in range(0, timeout):
if os.path.exists(path): if os.path.exists(path):
return return
time.sleep(1) time.sleep(1)
raise FileNotFoundError('Could not find {} after {} seconds'.format(path, timeout)) if logger:
logger.error('Could not find %s after %s seconds', path, timeout)
raise SystemExit
# we shouldn't need this if we are disabling the usb hub globally and nuking any past connections # we shouldn't need this if we are disabling the usb hub globally and nuking any past connections
#~ def freeBusyPath(path, logger=None): #~ def freeBusyPath(path, logger=None):

View File

@ -23,7 +23,7 @@ class KeypadListener(Thread):
devPath = '/dev/input/by-id/usb-04d9_1203-event-kbd' devPath = '/dev/input/by-id/usb-04d9_1203-event-kbd'
waitForPath(devPath) waitForPath(devPath, logger)
self._dev = InputDevice(devPath) self._dev = InputDevice(devPath)
self._dev.grab() self._dev.grab()
@ -109,7 +109,7 @@ class KeypadListener(Thread):
self._dev.ungrab() self._dev.ungrab()
logger.debug('Released keypad device') logger.debug('Released keypad device')
except IOError: except IOError:
logger.debug('Failed to release keypad device') logger.error('Failed to release keypad device')
except AttributeError: except AttributeError:
pass pass

View File

@ -2,6 +2,15 @@ import logging, os
from subprocess import run, PIPE, CalledProcessError from subprocess import run, PIPE, CalledProcessError
from logging.handlers import TimedRotatingFileHandler from logging.handlers import TimedRotatingFileHandler
"""
Logger conventions
- CRITICAL: for things that cause crashes. sends email
- ERROR: for things that cause startup/shutdown issues
- WARNING: for recoverable issues that may cause future problems
- INFO: state changes and sensor readings
- DEBUG: all extraneous crap
"""
# formats console output depending on whether we have gluster # formats console output depending on whether we have gluster
def _formatConsole(gluster = False): def _formatConsole(gluster = False):
c = '' if gluster else '[CONSOLE ONLY] ' c = '' if gluster else '[CONSOLE ONLY] '
@ -33,7 +42,7 @@ class GlusterFSHandler(TimedRotatingFileHandler):
if not os.path.exists(logdest): if not os.path.exists(logdest):
os.mkdir(logdest) os.mkdir(logdest)
elif os.path.isfile(logdest): elif os.path.isfile(logdest):
logger.critical('%s is present but is a file (vs a directory). ' \ logger.error('%s is present but is a file (vs a directory). ' \
'Please (re)move this file to prevent data loss', logdest) 'Please (re)move this file to prevent data loss', logdest)
raise SystemExit raise SystemExit
@ -62,10 +71,8 @@ class GlusterFSHandler(TimedRotatingFileHandler):
try: try:
run(cmd, check=True, stdout=PIPE, stderr=PIPE) run(cmd, check=True, stdout=PIPE, stderr=PIPE)
except CalledProcessError as e: except CalledProcessError as e:
# we assume that this will only get thrown when the logger is not
# active, so use fallback to get the explicit mount errors
stderr = e.stderr.decode('ascii').rstrip() stderr = e.stderr.decode('ascii').rstrip()
logger.critical(stderr) logger.error(stderr)
raise SystemExit raise SystemExit
def close(self): def close(self):

View File

@ -37,7 +37,7 @@ class State:
self.sound = sound self.sound = sound
def entry(self): def entry(self):
logger.debug('entering ' + self.name) logger.info('entering ' + self.name)
if self.sound: if self.sound:
self.sound.play() self.sound.play()
self.stateMachine.LED.blink = self.blinkLED self.stateMachine.LED.blink = self.blinkLED
@ -46,7 +46,7 @@ class State:
c() c()
def exit(self): def exit(self):
logger.debug('exiting ' + self.name) logger.info('exiting ' + self.name)
if self.sound: if self.sound:
self.sound.stop() self.sound.stop()
for c in self.exitCallbacks: for c in self.exitCallbacks:
@ -169,7 +169,7 @@ class StateMachine:
secretTable[secret]() secretTable[secret]()
logger.debug('Secret pipe listener received: \"%s\"', secret) logger.debug('Secret pipe listener received: \"%s\"', secret)
elif logger: elif logger:
logger.error('Secret pipe listener received invalid secret') logger.debug('Secret pipe listener received invalid secret')
self.secretListener = PipeListener( self.secretListener = PipeListener(
callback = secretCallback, callback = secretCallback,
@ -211,8 +211,8 @@ class StateMachine:
if hasattr(self, 'soundLib'): if hasattr(self, 'soundLib'):
self.soundLib.__del__() self.soundLib.__del__()
if hasattr(self, 'pipeListener'): if hasattr(self, 'secretListener'):
self.pipeListener.__del__() self.secretListener.__del__()
if hasattr(self, 'keypadListener'): if hasattr(self, 'keypadListener'):
self.keypadListener.__del__() self.keypadListener.__del__()

View File

@ -1,11 +1,13 @@
# this entire module is lovingly based on the gst-launch tool kindly provided """
# by the gstreamer wizards themselves...with unecessary crap cut out this entire module is lovingly based on the gst-launch tool kindly provided
by the gstreamer wizards themselves...with unecessary crap cut out
# we make the following assumptions here and optimize as such we make the following assumptions here and optimize as such
# - all streams are "live" - all streams are "live"
# - will not need EOS (no mp4s) - will not need EOS (no mp4s)
# - will not require SIGINT (this entire program won't understand them anyways) - will not require SIGINT (this entire program won't understand them anyways)
# - no tags or TOCs - no tags or TOCs
"""
from auxilary import async, waitForPath from auxilary import async, waitForPath
from threading import Thread from threading import Thread

View File

@ -45,7 +45,7 @@ def initWebInterface(stateMachine):
try: try:
check_output(['pidof', 'janus']) check_output(['pidof', 'janus'])
except CalledProcessError: except CalledProcessError:
logger.critical('Janus not running. Aborting') logger.error('Janus not running. Aborting')
raise SystemExit raise SystemExit
app = Flask(__name__) app = Flask(__name__)