From 01ab247a410488f86ac57cf07e22cca5e62bc92c Mon Sep 17 00:00:00 2001 From: Philipp Albrecht Date: Fri, 21 Jul 2023 14:20:26 +0200 Subject: Initialize logging as early as possible Now that `qutebrowser.utils.log` is a Qt-free zone, we can initialize logging before `machinery.init()` without crashing. --- qutebrowser/misc/earlyinit.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/qutebrowser/misc/earlyinit.py b/qutebrowser/misc/earlyinit.py index 72cc7b3f5..57e821784 100644 --- a/qutebrowser/misc/earlyinit.py +++ b/qutebrowser/misc/earlyinit.py @@ -295,12 +295,22 @@ def init_log(args): Args: args: The argparse namespace. """ - from qutebrowser.utils import log, qtlog + from qutebrowser.utils import log log.init_log(args) - qtlog.init(args) log.init.debug("Log initialized.") +def init_qtlog(args): + """Initialize Qt logging. + + Args: + args: The argparse namespace. + """ + from qutebrowser.utils import log, qtlog + qtlog.init(args) + log.init.debug("Qt log initialized.") + + def check_optimize_flag(): """Check whether qutebrowser is running with -OO.""" from qutebrowser.utils import log @@ -333,16 +343,18 @@ def early_init(args): Args: args: The argparse namespace. """ + # Init logging as early as possible + init_log(args) # First we initialize the faulthandler as early as possible, so we # theoretically could catch segfaults occurring later during earlyinit. init_faulthandler() # Then we configure the selected Qt wrapper info = machinery.init(args) + # Init Qt logging after machinery is initialized + init_qtlog(args) # Here we check if QtCore is available, and if not, print a message to the # console or via Tk. check_qt_available(info) - # Init logging as early as possible - init_log(args) # Now we can be sure QtCore is available, so we can print dialogs on # errors, so people only using the GUI notice them as well. check_libraries() -- cgit v1.2.3-54-g00ecf