Commit 09976876 authored by Domanski, Marian M.'s avatar Domanski, Marian M.
Browse files

write error log on crash due to unhandled error

parent fa815283
......@@ -117,3 +117,5 @@ MATLAB/
# FluEgg results
results/
error_log.txt
import os
import sys
from PyQt5.QtWidgets import QApplication
import traceback
import logging
from PyQt5.QtWidgets import QApplication, QMessageBox
from PyQt5.QtCore import Qt
import fluegg
import fluegggui
from fluegggui.gui import AppWindow
if __name__ == '__main__':
# Initialize the UI
fluegg.set_logging_level('critical')
app = QApplication(sys.argv)
w = AppWindow()
w.show()
sys.exit(app.exec_())
class FluEggApp:
def __init__(self):
log_filename = os.path.join(os.getcwd(), 'error_log.txt')
formatter = logging.Formatter(
'%(asctime)s - %(message)s')
fh = logging.FileHandler(log_filename, delay=True)
fh.setLevel(logging.ERROR)
fh.setFormatter(formatter)
fluegggui.logger.addHandler(fh)
fluegg.set_logging_level('error')
fluegggui.set_logging_level('error')
sys.excepthook = self.excepthook
self._app = None
self._w = None
self._log_file = log_filename
def excepthook(self, etype, evalue, tb):
fluegggui.logger.error('Unhandled error occurred')
for line in traceback.format_exception(etype, evalue, tb):
fluegggui.logger.error(line.strip())
QMessageBox.warning(
self._w, 'Unhandled Exception',
'An unhandled exception occurred.\n\n' +
'See the file\n{}\n'.format(self._log_file) +
'for more information.')
def run_app(self):
self._app = QApplication(sys.argv)
self._w = AppWindow()
self._w.show()
return self._app.exec_()
fluegg_app = FluEggApp()
app_exit_code = fluegg_app.run_app()
sys.exit(app_exit_code)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment