diff --git a/qutebrowser/utils/log.py b/qutebrowser/utils/log.py index 91ec7c821..a1e5ed280 100644 --- a/qutebrowser/utils/log.py +++ b/qutebrowser/utils/log.py @@ -26,6 +26,7 @@ import logging import contextlib import collections import faulthandler +import traceback from PyQt5.QtCore import (QtDebugMsg, QtWarningMsg, QtCriticalMsg, QtFatalMsg, qInstallMessageHandler) @@ -294,8 +295,16 @@ def qt_message_handler(msg_type, context, msg): msg += ("\n\nOn Archlinux, this should fix the problem:\n" " pacman -S libxkbcommon-x11") faulthandler.disable() + try: + frame = sys._getframe(1) + except (AttributeError, ValueError): + # sys._getframe might not exist in some Python implementations. + # It could raise ValueError if the stack is less than one level deep - + # this SHOULD never happen, but we're better safe than sorry here. + frame = None + stack = ''.join(traceback.format_stack(f=frame)) record = qt.makeRecord(name, level, context.file, context.line, msg, None, - None, func) + None, func, sinfo=stack) qt.handle(record)