Add logging wrapper for exceptions
This commit is contained in:
+2
-2
@@ -32,7 +32,7 @@ import logging
|
|||||||
from PyQt5.QtGui import QIcon
|
from PyQt5.QtGui import QIcon
|
||||||
from PyQt5.QtWidgets import QApplication, QErrorMessage
|
from PyQt5.QtWidgets import QApplication, QErrorMessage
|
||||||
|
|
||||||
from nw.error import exceptionHandler
|
from nw.error import exceptionHandler, logException
|
||||||
from nw.config import Config
|
from nw.config import Config
|
||||||
|
|
||||||
##
|
##
|
||||||
@@ -270,7 +270,7 @@ def main(sysArgs=None):
|
|||||||
info["CFBundleName"] = "novelWriter"
|
info["CFBundleName"] = "novelWriter"
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
logger.error("Failed to set application name")
|
logger.error("Failed to set application name")
|
||||||
logger.error(str(e))
|
logException(e)
|
||||||
|
|
||||||
# Import GUI (after dependency checks), and launch
|
# Import GUI (after dependency checks), and launch
|
||||||
from nw.guimain import GuiMain
|
from nw.guimain import GuiMain
|
||||||
|
|||||||
+19
-4
@@ -24,12 +24,31 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import logging
|
||||||
|
|
||||||
from PyQt5.QtCore import Qt
|
from PyQt5.QtCore import Qt
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
qApp, QDialog, QGridLayout, QStyle, QPlainTextEdit, QLabel,
|
qApp, QDialog, QGridLayout, QStyle, QPlainTextEdit, QLabel,
|
||||||
QDialogButtonBox
|
QDialogButtonBox
|
||||||
)
|
)
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
# =============================================================================================== #
|
||||||
|
# Utility Functions
|
||||||
|
# =============================================================================================== #
|
||||||
|
|
||||||
|
def logException(exObj):
|
||||||
|
"""Log the content of an exception message.
|
||||||
|
"""
|
||||||
|
exType, exValue, _ = sys.exc_info()
|
||||||
|
logger.error("%s: %s" % (exType.__name__, str(exValue).strip("'")))
|
||||||
|
|
||||||
|
# =============================================================================================== #
|
||||||
|
# Error Handler
|
||||||
|
# =============================================================================================== #
|
||||||
|
|
||||||
class NWErrorMessage(QDialog):
|
class NWErrorMessage(QDialog):
|
||||||
|
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
@@ -72,7 +91,6 @@ class NWErrorMessage(QDialog):
|
|||||||
"""Generate a message and append session data, error info and
|
"""Generate a message and append session data, error info and
|
||||||
error traceback.
|
error traceback.
|
||||||
"""
|
"""
|
||||||
import sys
|
|
||||||
from traceback import format_tb
|
from traceback import format_tb
|
||||||
from nw import __issuesurl__, __version__
|
from nw import __issuesurl__, __version__
|
||||||
from PyQt5.Qt import PYQT_VERSION_STR
|
from PyQt5.Qt import PYQT_VERSION_STR
|
||||||
@@ -133,15 +151,12 @@ class NWErrorMessage(QDialog):
|
|||||||
|
|
||||||
# END Class NWErrorMessage
|
# END Class NWErrorMessage
|
||||||
|
|
||||||
|
|
||||||
def exceptionHandler(exType, exValue, exTrace):
|
def exceptionHandler(exType, exValue, exTrace):
|
||||||
"""Function to catch unhandled global exceptions.
|
"""Function to catch unhandled global exceptions.
|
||||||
"""
|
"""
|
||||||
import logging
|
|
||||||
from traceback import print_tb
|
from traceback import print_tb
|
||||||
from PyQt5.QtWidgets import qApp
|
from PyQt5.QtWidgets import qApp
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
logger.critical("%s: %s" % (exType.__name__, str(exValue)))
|
logger.critical("%s: %s" % (exType.__name__, str(exValue)))
|
||||||
print_tb(exTrace)
|
print_tb(exTrace)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user