Add excepthook for verbose. Bugfixes

Enabled exception hook for all cases
This commit is contained in:
Bas Stottelaar
2014-04-01 16:08:29 +02:00
parent 2add9fa264
commit e409859c35
3 changed files with 23 additions and 3 deletions

View File

@@ -176,7 +176,7 @@ def main():
except KeyboardInterrupt:
headphones.SIGNAL = 'shutdown'
else:
logger.info('Received signal: %d', headphones.SIGNAL)
logger.info('Received signal: %s', headphones.SIGNAL)
if headphones.SIGNAL == 'shutdown':
headphones.shutdown()
elif headphones.SIGNAL == 'restart':

View File

@@ -775,8 +775,8 @@ def daemonize():
os.dup2(so.fileno(), sys.stdout.fileno())
os.dup2(se.fileno(), sys.stderr.fileno())
pid = str(os.getpid())
logger.info('Daemonized to PID: %s' % pid)
pid = os.getpid()
logger.info('Daemonized to PID: %d', pid)
if CREATEPID:
logger.info("Writing PID %d to %s", pid, PIDFILE)

View File

@@ -14,7 +14,9 @@
# along with Headphones. If not, see <http://www.gnu.org/licenses/>.
import os
import sys
import logging
import traceback
import headphones
from logging import handlers
@@ -79,6 +81,24 @@ def initLogger(verbose=1):
logger.addHandler(console_handler)
# Any exceptions uncaught will pass through this handle
sys.excepthook = excepthook
def excepthook(*exception_info):
"""
Log uncaught exceptions via the logger.error() method. This is especially
useful for daemons.
"""
# We should always catch this to prevent loops!
try:
logger.error("Uncaught excaption: %s", traceback.print_exception(*exception_info))
except:
pass
# Original excepthook
sys.__excepthook__(*exception_info)
# Expose logger methods
info = logger.info
warn = logger.warn