Skip to content

Commit c7ad329

Browse files
committed
Add log file to catch unexpected crash
1 parent 7b6d309 commit c7ad329

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/gui/main.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77

88
import sys
9+
import logging
910
import webbrowser
1011

1112
from PyQt5 import QtWidgets, QtCore, QtGui
@@ -20,6 +21,18 @@
2021
from src.convert import convert_dir_text
2122
from src.pdf.bookmark import add_bookmark
2223

24+
logging.basicConfig(level=logging.DEBUG,
25+
format='%(asctime)s - %(levelname)s - %(message)s',
26+
filename='pdfdir.log',
27+
filemode='a')
28+
29+
30+
def log_uncaught_exceptions(ex_cls, ex, tb):
31+
text = '{}: {}:\n'.format(ex_cls.__name__, ex)
32+
logging.critical(text, exc_info=(ex_cls, ex, tb))
33+
34+
35+
sys.excepthook = log_uncaught_exceptions
2336

2437
QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)
2538

0 commit comments

Comments
 (0)