log exceptions only in debug mode

This commit is contained in:
Ozzieisaacs 2020-12-11 16:46:02 +01:00
parent 8b605aeaa8
commit d9b22fd513
7 changed files with 44 additions and 12 deletions

View File

@ -259,7 +259,10 @@ def delete_book(book_id, book_format, jsonResponse):
filter(db.Data.format == book_format).delete() filter(db.Data.format == book_format).delete()
calibre_db.session.commit() calibre_db.session.commit()
except Exception as e: except Exception as e:
log.exception(e) if config.config_log_level == logger.logging.DEBUG:
log.exception(e)
else:
log.error(e)
calibre_db.session.rollback() calibre_db.session.rollback()
else: else:
# book not found # book not found

View File

@ -156,5 +156,8 @@ def on_received_watch_confirmation():
move(os.path.join(tmp_dir, "tmp_metadata.db"), dbpath) move(os.path.join(tmp_dir, "tmp_metadata.db"), dbpath)
calibre_db.reconnect_db(config, ub.app_DB_path) calibre_db.reconnect_db(config, ub.app_DB_path)
except Exception as e: except Exception as e:
log.exception(e) if config.config_log_level == logger.logging.DEBUG:
log.exception(e)
else:
log.error(e)
return '' return ''

View File

@ -199,7 +199,10 @@ def getDrive(drive=None, gauth=None):
except RefreshError as e: except RefreshError as e:
log.error("Google Drive error: %s", e) log.error("Google Drive error: %s", e)
except Exception as e: except Exception as e:
log.exception(e) if config.config_log_level == logger.logging.DEBUG:
log.exception(e)
else:
log.error(e)
else: else:
# Initialize the saved creds # Initialize the saved creds
gauth.Authorize() gauth.Authorize()

View File

@ -562,8 +562,10 @@ def get_book_cover_internal(book, use_generic_cover_on_failure):
log.error('%s/cover.jpg not found on Google Drive', book.path) log.error('%s/cover.jpg not found on Google Drive', book.path)
return get_cover_on_failure(use_generic_cover_on_failure) return get_cover_on_failure(use_generic_cover_on_failure)
except Exception as e: except Exception as e:
log.exception(e) if config.config_log_level == logger.logging.DEBUG:
# traceback.print_exc() log.exception(e)
else:
log.error(e)
return get_cover_on_failure(use_generic_cover_on_failure) return get_cover_on_failure(use_generic_cover_on_failure)
else: else:
cover_file_path = os.path.join(config.config_calibre_dir, book.path) cover_file_path = os.path.join(config.config_calibre_dir, book.path)

View File

@ -88,7 +88,10 @@ def register_user_with_oauth(user=None):
try: try:
ub.session.commit() ub.session.commit()
except Exception as e: except Exception as e:
log.exception(e) if config.config_log_level == logger.logging.DEBUG:
log.exception(e)
else:
log.error(e)
ub.session.rollback() ub.session.rollback()
@ -207,7 +210,10 @@ if ub.oauth_support:
ub.session.add(oauth_entry) ub.session.add(oauth_entry)
ub.session.commit() ub.session.commit()
except Exception as e: except Exception as e:
log.exception(e) if config.config_log_level == logger.logging.DEBUG:
log.exception(e)
else:
log.error(e)
ub.session.rollback() ub.session.rollback()
# Disable Flask-Dance's default behavior for saving the OAuth token # Disable Flask-Dance's default behavior for saving the OAuth token
@ -239,7 +245,10 @@ if ub.oauth_support:
flash(_(u"Link to %(oauth)s Succeeded", oauth=provider_name), category="success") flash(_(u"Link to %(oauth)s Succeeded", oauth=provider_name), category="success")
return redirect(url_for('web.profile')) return redirect(url_for('web.profile'))
except Exception as e: except Exception as e:
log.exception(e) if config.config_log_level == logger.logging.DEBUG:
log.exception(e)
else:
log.error(e)
ub.session.rollback() ub.session.rollback()
else: else:
flash(_(u"Login failed, No User Linked With OAuth Account"), category="error") flash(_(u"Login failed, No User Linked With OAuth Account"), category="error")
@ -286,7 +295,10 @@ if ub.oauth_support:
logout_oauth_user() logout_oauth_user()
flash(_(u"Unlink to %(oauth)s Succeeded", oauth=oauth_check[provider]), category="success") flash(_(u"Unlink to %(oauth)s Succeeded", oauth=oauth_check[provider]), category="success")
except Exception as e: except Exception as e:
log.exception(e) if config.config_log_level == logger.logging.DEBUG:
log.exception(e)
else:
log.error(e)
ub.session.rollback() ub.session.rollback()
flash(_(u"Unlink to %(oauth)s Failed", oauth=oauth_check[provider]), category="error") flash(_(u"Unlink to %(oauth)s Failed", oauth=oauth_check[provider]), category="error")
except NoResultFound: except NoResultFound:

View File

@ -210,7 +210,10 @@ class CalibreTask:
self._progress = x self._progress = x
def _handleError(self, error_message): def _handleError(self, error_message):
log.exception(error_message) if logger.is_debug_enabled():
log.exception(error_message)
else:
log.error(error_message)
self.stat = STAT_FAIL self.stat = STAT_FAIL
self.progress = 1 self.progress = 1
self.error = error_message self.error = error_message

View File

@ -316,7 +316,10 @@ def import_ldap_users():
try: try:
new_users = services.ldap.get_group_members(config.config_ldap_group_name) new_users = services.ldap.get_group_members(config.config_ldap_group_name)
except (services.ldap.LDAPException, TypeError, AttributeError, KeyError) as e: except (services.ldap.LDAPException, TypeError, AttributeError, KeyError) as e:
log.exception(e) if config.config_log_level == logger.logging.DEBUG:
log.exception(e)
else:
log.error(e)
showtext['text'] = _(u'Error: %(ldaperror)s', ldaperror=e) showtext['text'] = _(u'Error: %(ldaperror)s', ldaperror=e)
return json.dumps(showtext) return json.dumps(showtext)
if not new_users: if not new_users:
@ -344,7 +347,10 @@ def import_ldap_users():
try: try:
user_data = services.ldap.get_object_details(user=user_identifier, query_filter=query_filter) user_data = services.ldap.get_object_details(user=user_identifier, query_filter=query_filter)
except AttributeError as e: except AttributeError as e:
log.exception(e) if config.config_log_level == logger.logging.DEBUG:
log.exception(e)
else:
log.error(e)
continue continue
if user_data: if user_data:
user_login_field = extract_dynamic_field_from_filter(user, config.config_ldap_user_object) user_login_field = extract_dynamic_field_from_filter(user, config.config_ldap_user_object)