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):
self.stop()
def waitForPath(path, timeout=30):
def waitForPath(path, logger=None, timeout=30):
for i in range(0, timeout):
if os.path.exists(path):
return
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
#~ def freeBusyPath(path, logger=None):

View File

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

View File

@ -2,6 +2,15 @@ import logging, os
from subprocess import run, PIPE, CalledProcessError
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
def _formatConsole(gluster = False):
c = '' if gluster else '[CONSOLE ONLY] '
@ -33,7 +42,7 @@ class GlusterFSHandler(TimedRotatingFileHandler):
if not os.path.exists(logdest):
os.mkdir(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)
raise SystemExit
@ -62,10 +71,8 @@ class GlusterFSHandler(TimedRotatingFileHandler):
try:
run(cmd, check=True, stdout=PIPE, stderr=PIPE)
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()
logger.critical(stderr)
logger.error(stderr)
raise SystemExit
def close(self):

View File

@ -37,7 +37,7 @@ class State:
self.sound = sound
def entry(self):
logger.debug('entering ' + self.name)
logger.info('entering ' + self.name)
if self.sound:
self.sound.play()
self.stateMachine.LED.blink = self.blinkLED
@ -46,7 +46,7 @@ class State:
c()
def exit(self):
logger.debug('exiting ' + self.name)
logger.info('exiting ' + self.name)
if self.sound:
self.sound.stop()
for c in self.exitCallbacks:
@ -169,7 +169,7 @@ class StateMachine:
secretTable[secret]()
logger.debug('Secret pipe listener received: \"%s\"', secret)
elif logger:
logger.error('Secret pipe listener received invalid secret')
logger.debug('Secret pipe listener received invalid secret')
self.secretListener = PipeListener(
callback = secretCallback,
@ -211,8 +211,8 @@ class StateMachine:
if hasattr(self, 'soundLib'):
self.soundLib.__del__()
if hasattr(self, 'pipeListener'):
self.pipeListener.__del__()
if hasattr(self, 'secretListener'):
self.secretListener.__del__()
if hasattr(self, 'keypadListener'):
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
# - all streams are "live"
# - will not need EOS (no mp4s)
# - will not require SIGINT (this entire program won't understand them anyways)
# - no tags or TOCs
we make the following assumptions here and optimize as such
- all streams are "live"
- will not need EOS (no mp4s)
- will not require SIGINT (this entire program won't understand them anyways)
- no tags or TOCs
"""
from auxilary import async, waitForPath
from threading import Thread

View File

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