logging_handler: Resolve exception logging

This commit is contained in:
Mykola Grymalyuk
2023-05-22 10:58:49 -06:00
parent 1f23ceef7f
commit 422eee04b7
3 changed files with 25 additions and 11 deletions

View File

@@ -1,10 +1,15 @@
import logging
import sys
import threading
import os
import sys
import logging
import threading
import traceback
import subprocess
import applescript
from pathlib import Path
from resources import constants
class InitializeLoggingSupport:
"""
@@ -26,10 +31,12 @@ class InitializeLoggingSupport:
"""
def __init__(self) -> None:
def __init__(self, global_constants: constants.Constants) -> None:
self.log_filename: str = "OpenCore-Patcher.log"
self.log_filepath: Path = None
self.constants: constants.Constants = global_constants
self.original_excepthook: sys = sys.excepthook
self.original_thread_excepthook: threading = threading.excepthook
@@ -43,10 +50,6 @@ class InitializeLoggingSupport:
self._fix_file_permission()
def __del__(self) -> None:
self._restore_original_excepthook()
def _initialize_logging_path(self) -> None:
"""
Initialize logging framework storage path
@@ -156,6 +159,15 @@ class InitializeLoggingSupport:
"""
logging.error("Uncaught exception in main thread", exc_info=(type, value, tb))
error_msg = f"OpenCore Legacy Patcher encountered the following internal error:\n\n"
error_msg += f"{type.__name__}: {value}"
if tb:
error_msg += f"\n\n{traceback.extract_tb(tb)[-1]}"
error_msg += "\n\nPlease report this error on our Discord server."
applescript.AppleScript(f'display dialog "{error_msg}" with title "OpenCore Legacy Patcher ({self.constants.patcher_version})" buttons {{"OK"}} default button "OK" with icon caution giving up after 30').run()
def custom_thread_excepthook(args) -> None:
"""
Reroute traceback in spawned thread to logging module