exception decorator and mail send for errors and changes to rec state checker
This commit is contained in:
@@ -3,7 +3,10 @@
|
||||
Backend base module
|
||||
"""
|
||||
import logging
|
||||
from io import StringIO
|
||||
from logging.config import dictConfig
|
||||
from typing import Union
|
||||
|
||||
import coloredlogs as coloredlogs
|
||||
import jwt
|
||||
import requests
|
||||
@@ -25,7 +28,6 @@ __email__ = "it@t-kurze.de"
|
||||
# __status__ = "Production"
|
||||
__status__ = "Development"
|
||||
|
||||
|
||||
dictConfig({
|
||||
'version': 1,
|
||||
'formatters': {
|
||||
@@ -66,7 +68,7 @@ dictConfig({
|
||||
},
|
||||
},
|
||||
'loggers': {
|
||||
'mal': {
|
||||
'lrc': {
|
||||
'level': Config.LOG_LEVEL,
|
||||
'handlers': ['wsgi', 'file', 'errors_file']
|
||||
}
|
||||
@@ -78,18 +80,34 @@ dictConfig({
|
||||
})
|
||||
|
||||
main_logger = logging.getLogger("lrc")
|
||||
|
||||
# following might be dangerous, as buffer might be filled without a mechanism to empty it
|
||||
# error_log_stream = StringIO()
|
||||
# error_log_stream_handler = logging.StreamHandler(stream=error_log_stream)
|
||||
# error_log_stream_handler.setLevel(logging.ERROR)
|
||||
# main_logger.addHandler(error_log_stream_handler)
|
||||
|
||||
coloredlogs.install(level='DEBUG', logger=main_logger)
|
||||
|
||||
|
||||
class LrcException(Exception):
|
||||
def __init__(self, message: str, html_code: int = None):
|
||||
super().__init__(message)
|
||||
def __init__(self, message_or_exception: Union[str, Exception], html_code: int = None):
|
||||
if isinstance(message_or_exception, str):
|
||||
super().__init__(message_or_exception)
|
||||
self.type = None
|
||||
else:
|
||||
super().__init__(str(message_or_exception))
|
||||
self.type = type(message_or_exception)
|
||||
self.html_code = html_code
|
||||
|
||||
def __repr__(self):
|
||||
if self.type is None:
|
||||
msg = "LRC Exception: \"{}\"".format(', '.join(super().args))
|
||||
else:
|
||||
msg = "LRC Exception: (original Exception: {}) \"{}\"".format(self.type, ', '.join(super().args))
|
||||
if self.html_code is not None:
|
||||
return "LRC Exception: \"{}\" (HTML Code: {})".format(', '.join(super().args), self.html_code)
|
||||
return ', '.join(super().args)
|
||||
msg += " (HTML Code: {})".format(self.html_code)
|
||||
return msg
|
||||
|
||||
def __str__(self):
|
||||
return self.__repr__()
|
||||
|
||||
Reference in New Issue
Block a user