all repos — listfix @ d3783f98e966f4311b5173dd99f8651893b74440

Postfix Mailing List Software; Maintained on behalf the of Agency Economy Incorporated NFP.

listfix/errors.py (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
import sys
from .log import Log

class Errors:

	def __init__(self, debug=False):
		self.debug = debug
		self._exception_handler = None
		self.log = Log()

	def set_exception_handler(self):
		self._exception_handler = sys.excepthook
		sys.excepthook = self.exception_handler

	def exception_handler(self, exception_type, exception, traceback):
		self.log.error(f"{exception_type.__name__}, {exception}")
		if (self.debug):
			self._exception_handler(exception_type, exception, traceback)
		else:
			print(f"Error: {exception}")