Improved logging (right stacklevel on mail exceptions)

Updated jsonschema requirements
This commit is contained in:
Ozzieisaacs 2021-12-25 10:35:08 +01:00
parent 785726deee
commit 573c9f9fb4
4 changed files with 12 additions and 17 deletions

View File

@ -42,20 +42,15 @@ logging.addLevelName(logging.CRITICAL, "CRIT")
class _Logger(logging.Logger):
def debug_or_exception(self, message, *args, **kwargs):
def debug_or_exception(self, message, stacklevel=2, *args, **kwargs):
if sys.version_info > (3, 7):
if is_debug_enabled():
self.exception(message, stacklevel=2, *args, **kwargs)
self.exception(message, stacklevel=stacklevel, *args, **kwargs)
else:
self.error(message, stacklevel=2, *args, **kwargs)
elif sys.version_info > (3, 0):
if is_debug_enabled():
self.exception(message, stack_info=True, *args, **kwargs)
else:
self.error(message, *args, **kwargs)
self.error(message, stacklevel=stacklevel, *args, **kwargs)
else:
if is_debug_enabled():
self.exception(message, *args, **kwargs)
self.exception(message, stack_info=True, *args, **kwargs)
else:
self.error(message, *args, **kwargs)

View File

@ -158,10 +158,10 @@ class TaskEmail(CalibreTask):
else:
self.send_gmail_email(msg)
except MemoryError as e:
log.debug_or_exception(e)
log.debug_or_exception(e, stacklevel=3)
self._handleError(u'MemoryError sending e-mail: {}'.format(str(e)))
except (smtplib.SMTPException, smtplib.SMTPAuthenticationError) as e:
log.debug_or_exception(e)
log.debug_or_exception(e, stacklevel=3)
if hasattr(e, "smtp_error"):
text = e.smtp_error.decode('utf-8').replace("\n", '. ')
elif hasattr(e, "message"):
@ -171,11 +171,11 @@ class TaskEmail(CalibreTask):
else:
text = ''
self._handleError(u'Smtplib Error sending e-mail: {}'.format(text))
except socket.error as e:
log.debug_or_exception(e)
except (socket.error) as e:
log.debug_or_exception(e, stacklevel=3)
self._handleError(u'Socket Error sending e-mail: {}'.format(e.strerror))
except Exception as ex:
log.debug_or_exception(ex)
log.debug_or_exception(ex, stacklevel=3)
self._handleError(u'Error sending e-mail: {}'.format(ex))
def send_standard_email(self, msg):
@ -248,7 +248,7 @@ class TaskEmail(CalibreTask):
data = file_.read()
file_.close()
except IOError as e:
log.debug_or_exception(e)
log.debug_or_exception(e, stacklevel=3)
log.error(u'The requested file could not be read. Maybe wrong permissions?')
return None
# Set mimetype

View File

@ -38,4 +38,4 @@ natsort>=2.2.0,<8.1.0
comicapi>=2.2.0,<2.3.0
#Kobo integration
jsonschema>=3.2.0,<4.3.0
jsonschema>=3.2.0,<4.4.0

View File

@ -87,7 +87,7 @@ comics =
natsort>=2.2.0,<8.1.0
comicapi>= 2.2.0,<2.3.0
kobo =
jsonschema>=3.2.0,<4.3.0
jsonschema>=3.2.0,<4.4.0