mirror of
https://github.com/rembo10/headphones.git
synced 2026-05-19 10:05:30 +01:00
Add excepthook for verbose. Bugfixes
Enabled exception hook for all cases
This commit is contained in:
@@ -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':
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user