From a64775a0f97d256dabb6830c61236439f3edf657 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sat, 21 Jun 2014 22:40:31 +0200 Subject: [PATCH] Improve logging messages --- qutebrowser/app.py | 32 ++++++++++++++++++---------- qutebrowser/browser/downloads.py | 3 ++- qutebrowser/browser/webpage.py | 4 ++-- qutebrowser/config/config.py | 3 ++- qutebrowser/config/conftypes.py | 1 - qutebrowser/config/style.py | 2 +- qutebrowser/models/completion.py | 11 ++++++---- qutebrowser/models/downloadmodel.py | 7 +----- qutebrowser/network/qutescheme.py | 4 ++-- qutebrowser/utils/usertypes.py | 3 ++- qutebrowser/utils/version.py | 9 +++++--- qutebrowser/widgets/crash.py | 9 +++++--- qutebrowser/widgets/mainwindow.py | 7 ++++-- qutebrowser/widgets/tabbedbrowser.py | 8 +++---- qutebrowser/widgets/tabwidget.py | 8 ++----- 15 files changed, 63 insertions(+), 48 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 36fdc77ce..369cd1fd6 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -253,10 +253,11 @@ class Application(QApplication): # This means another instance is probably still running and # didn't remove the file. As we can't write to the same file, # we just leave faulthandler as it is and log to stderr. - log.init.warn("Empty crash.log detected. This means either " + log.init.warn("Empty crash log detected. This means either " "another instance is running (then ignore this " "warning) or the file is lying here because " - "of some earlier crash (then delete it).") + "of some earlier crash (then delete {}).".format( + logname)) self._crashlogfile = None else: # There's no log file, so we can use this to display crashes to the @@ -446,7 +447,8 @@ class Application(QApplication): if url: pages.append(url) except Exception as e: # pylint: disable=broad-except - log.init.debug(e) + log.destroy.debug("Error while recovering tab: {}: {}".format( + e.__class__.__name__, e)) return pages def _save_geometry(self): @@ -486,7 +488,8 @@ class Application(QApplication): self.shutdown() return except Exception as e: - log.destroy.debug(e) + log.init.debug("Error while shutting down: {}: {}".format( + e.__class__.__name__, e)) self.quit() return @@ -498,36 +501,42 @@ class Application(QApplication): try: pages = self._recover_pages() except Exception as e: - log.destroy.debug(e) + log.destroy.debug("Error while recovering pages: {}: {}".format( + e.__class__.__name__, e)) pages = [] try: history = self.mainwindow.status.cmd.history[-5:] except Exception as e: - log.destroy.debug(e) + log.destroy.debug("Error while getting history: {}: {}".format( + e.__class__.__name__, e)) history = [] try: widgets = self.get_all_widgets() except Exception as e: - log.destroy.debug(e) + log.destroy.debug("Error while getting widgets: {}: {}".format( + e.__class__.__name__, e)) widgets = "" try: objects = self.get_all_objects() except Exception as e: - log.destroy.debug(e) + log.destroy.debug("Error while getting objects: {}: {}".format( + e.__class__.__name__, e)) objects = "" # Try to shutdown gracefully try: self.shutdown(do_quit=False) except Exception as e: - log.destroy.debug(e) + log.destroy.debug("Error while shutting down: {}: {}".format( + e.__class__.__name__, e)) try: self.lastWindowClosed.disconnect(self.shutdown) except TypeError as e: - log.destroy.warning("Preventing shutdown failed ({}).") + log.destroy.debug("Error while preventing shutdown: {}: {}".format( + e.__class__.__name__, e)) QApplication.closeAllWindows() self._crashdlg = ExceptionCrashDialog(pages, history, exc, widgets, objects) @@ -575,7 +584,8 @@ class Application(QApplication): # try: # argv.remove(page) # except ValueError as e: - # logger.destroy.debug(e) + # logger.destroy.debug("Error while removing page: {}: " + # "{}".format(e.__class__.__name__, e)) # argv = [sys.executable] + argv + pages # log.procs.debug("Running {} with args {} (PYTHONPATH={})".format( # sys.executable, argv, pythonpath)) diff --git a/qutebrowser/browser/downloads.py b/qutebrowser/browser/downloads.py index 23db7ca39..5c7ef010c 100644 --- a/qutebrowser/browser/downloads.py +++ b/qutebrowser/browser/downloads.py @@ -348,7 +348,8 @@ class DownloadManager(QObject): bytes(reply.rawHeader('Content-Disposition'))) filename = content_disposition.filename_unsafe except UnicodeDecodeError as e: - logger.warning(e) + logger.warning("Error while getting filename: {}: {}".format( + e.__class__.__name__, e)) filename = None else: filename = None diff --git a/qutebrowser/browser/webpage.py b/qutebrowser/browser/webpage.py index d5ebbbdc3..f6c714f1a 100644 --- a/qutebrowser/browser/webpage.py +++ b/qutebrowser/browser/webpage.py @@ -197,8 +197,8 @@ class BrowserPage(QWebPage): """ try: handler = self._extension_handlers[ext] - except KeyError as e: - log.webview.warning(e) + except KeyError: + log.webview.warning("Extension {} not supported!".format(ext)) return super().extension(ext, opt, out) return handler(opt, out) diff --git a/qutebrowser/config/config.py b/qutebrowser/config/config.py index 4fe4ee0a3..408053a7b 100644 --- a/qutebrowser/config/config.py +++ b/qutebrowser/config/config.py @@ -171,7 +171,8 @@ class ConfigManager(QObject): try: desc = self.sections[sectname].descriptions[optname] except KeyError as e: - log.misc.debug(e) + log.misc.debug("No description for {}.{}! ({}: {})".format( + sectname, optname, e.__class__.__name__, e)) continue for descline in desc.splitlines(): lines += wrapper.wrap(descline) diff --git a/qutebrowser/config/conftypes.py b/qutebrowser/config/conftypes.py index cc3e09ec8..6810910d2 100644 --- a/qutebrowser/config/conftypes.py +++ b/qutebrowser/config/conftypes.py @@ -30,7 +30,6 @@ from PyQt5.QtNetwork import QNetworkProxy import qutebrowser.commands.utils as cmdutils from qutebrowser.utils.misc import get_standard_dir -from qutebrowser.utils.log import misc as logger class ValidationError(ValueError): diff --git a/qutebrowser/config/style.py b/qutebrowser/config/style.py index ffe4c0013..47f58ef02 100644 --- a/qutebrowser/config/style.py +++ b/qutebrowser/config/style.py @@ -107,7 +107,7 @@ class ColorDict(dict): try: val = super().__getitem__(key) except KeyError as e: - logger.warning(e) + logger.warning("No color defined for {}!".format(e)) return '' if isinstance(val, QColor): # This could happen when accidentaly declarding something as diff --git a/qutebrowser/models/completion.py b/qutebrowser/models/completion.py index 8f9b0fa89..f9b452f1d 100644 --- a/qutebrowser/models/completion.py +++ b/qutebrowser/models/completion.py @@ -1,4 +1,4 @@ -# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:) # Copyright 2014 Florian Bruhin (The Compiler) # @@ -63,7 +63,9 @@ class SettingOptionCompletionModel(BaseCompletionModel): try: desc = sectdata.descriptions[name] except (KeyError, AttributeError) as e: - logger.debug(e) + logger.debug("Error while getting setting description for " + "{}.{}: {}: {}".format(section, name, + e.__class__.__name__, e)) desc = "" value = config.get(section, name, raw=True) _valitem, _descitem, miscitem = self.new_item(cat, name, desc, @@ -77,8 +79,9 @@ class SettingOptionCompletionModel(BaseCompletionModel): return try: item = self._misc_items[option] - except KeyError as e: - logger.debug(e) + except KeyError: + logger.debug("Couldn't get item {}.{} from model!".format( + section, option)) # changed before init return val = config.get(section, option, raw=True) diff --git a/qutebrowser/models/downloadmodel.py b/qutebrowser/models/downloadmodel.py index 8651c5956..8f4ceb4e9 100644 --- a/qutebrowser/models/downloadmodel.py +++ b/qutebrowser/models/downloadmodel.py @@ -25,7 +25,6 @@ from PyQt5.QtWidgets import QApplication import qutebrowser.config.config as config from qutebrowser.utils.usertypes import enum -from qutebrowser.utils.log import downloads as logger from qutebrowser.utils.misc import qt_ensure_valid @@ -78,11 +77,7 @@ class DownloadModel(QAbstractListModel): if index.parent().isValid() or index.column() != 0: return QVariant() - try: - item = self.downloadmanager.downloads[index.row()] - except IndexError as e: - logger.debug(e) - return QVariant() + item = self.downloadmanager.downloads[index.row()] if role == Qt.DisplayRole: data = str(item) elif role == Qt.ForegroundRole: diff --git a/qutebrowser/network/qutescheme.py b/qutebrowser/network/qutescheme.py index abd4c6e33..1afd568cf 100644 --- a/qutebrowser/network/qutescheme.py +++ b/qutebrowser/network/qutescheme.py @@ -86,8 +86,8 @@ class QuteSchemeHandler(SchemeHandler): request.url().toDisplayString(), path)) try: handler = getattr(QuteHandlers, path) - except AttributeError as e: - logutils.misc.debug(e) + except AttributeError: + logutils.misc.warning("No handler found for {}!".format(path)) data = bytes() else: data = handler() diff --git a/qutebrowser/utils/usertypes.py b/qutebrowser/utils/usertypes.py index dde305863..ecbc6d4eb 100644 --- a/qutebrowser/utils/usertypes.py +++ b/qutebrowser/utils/usertypes.py @@ -299,7 +299,8 @@ class Question(QObject): # FIXME # We seem to get "pyqtSignal must be bound to a QObject, not # 'Question' here, which makes no sense at all..." - logger.debug(e) + logger.debug("Error while aborting question: {}: {}".format( + e.__class__.__name__, e)) class Timer(QTimer): diff --git a/qutebrowser/utils/version.py b/qutebrowser/utils/version.py index 53c1bc3bb..685dfded0 100644 --- a/qutebrowser/utils/version.py +++ b/qutebrowser/utils/version.py @@ -83,7 +83,8 @@ def _git_str(): gitpath = os.path.join(os.path.dirname(os.path.realpath(__file__)), os.path.pardir, os.path.pardir) except NameError as e: - logger.debug(e) + logger.debug("Error while getting git path: {}: {}".format( + e.__class__.__name__, e)) else: commit = _git_str_subprocess(gitpath) if commit is not None: @@ -126,7 +127,8 @@ def _release_info(): with open(fn, 'r') as f: data.append((fn, ''.join(f.readlines()))) except IOError as e: - logger.warn(e) + logger.warn("Error while reading {}: {}: {}".format( + fn, e.__class__.__name__, e)) return data @@ -147,7 +149,8 @@ def _module_versions(): lines.append('SIP: {}'.format( sipconfig.Configuration().sip_version_str)) except (AttributeError, TypeError) as e: - logger.warn(e) + logger.warn("Error while getting SIP version: {}: {}".format( + e.__class__.__name__, e)) lines.append('SIP: ?') try: diff --git a/qutebrowser/widgets/crash.py b/qutebrowser/widgets/crash.py index 6ebf7a233..2536c6576 100644 --- a/qutebrowser/widgets/crash.py +++ b/qutebrowser/widgets/crash.py @@ -122,7 +122,8 @@ class _CrashDialog(QDialog): self._crash_info.append(("Config", config.instance().dump_userconfig())) except AttributeError as e: - self._crash_info.append(("Config", str(e))) + self._crash_info.append(("Config", "{}: {}".format( + e.__class__.__name__, e))) def _format_crash_info(self): """Format the gathered crash info to be displayed. @@ -145,7 +146,8 @@ class _CrashDialog(QDialog): try: url = utils.pastebin(self._txt.toPlainText()) except (URLError, ValueError) as e: - self._url.setText('Error while reporting: {}'.format(str(e))) + self._url.setText('Error while reporting: {}: {}'.format( + e.__class__.__name__, e)) return self._btn_pastebin.setEnabled(False) self._url.setText("Reported to: {}".format(url, url)) @@ -218,7 +220,8 @@ class ExceptionCrashDialog(_CrashDialog): self._crash_info.append(("Debug log", logutils.ram_handler.dump_log())) except AttributeError as e: - self._crash_info.append(("Debug log", str(e))) + self._crash_info.append(("Debug log", "{}: {}".format( + e.__class__.__name__, e))) class FatalCrashDialog(_CrashDialog): diff --git a/qutebrowser/widgets/mainwindow.py b/qutebrowser/widgets/mainwindow.py index 62f9a163f..8da51136e 100644 --- a/qutebrowser/widgets/mainwindow.py +++ b/qutebrowser/widgets/mainwindow.py @@ -60,15 +60,18 @@ class MainWindow(QWidget): geom = b64decode(stateconf['geometry']['mainwindow'], validate=True) except (KeyError, binascii.Error) as e: - logger.warn(e) + logger.warn("Error while reading geometry: {}: {}".format( + e.__class__.__name__, e)) self._set_default_geometry() else: try: ok = self.restoreGeometry(geom) except KeyError: - logger.warn(e) + logger.warn("Error while restoring geometry: {}: {}".format( + e.__class__.__name__, e)) self._set_default_geometry() if not ok: + logger.warn("Error while restoring geometry.") self._set_default_geometry() self._vbox = QVBoxLayout(self) diff --git a/qutebrowser/widgets/tabbedbrowser.py b/qutebrowser/widgets/tabbedbrowser.py index 71ffce1ae..16e1264ae 100644 --- a/qutebrowser/widgets/tabbedbrowser.py +++ b/qutebrowser/widgets/tabbedbrowser.py @@ -135,9 +135,8 @@ class TabbedBrowser(TabWidget): """ try: self._tabs.remove(tab) - except ValueError as e: - log.destroy.exception("tab {} could not be removed ({})".format( - tab, e)) + except ValueError: + log.destroy.exception("tab {} could not be removed") log.destroy.debug("Tabs after removing: {}".format(self._tabs)) if not self._tabs: # all tabs shut down log.destroy.debug("Tab shutdown complete.") @@ -201,7 +200,8 @@ class TabbedBrowser(TabWidget): try: self.currentChanged.disconnect() except TypeError as e: - log.destroy.debug(e) + log.destroy.debug("Error while shutting down tabs: {}: {}".format( + e.__class__.__name__, e)) tabcount = self.count() if tabcount == 0: log.destroy.debug("No tabs -> shutdown complete") diff --git a/qutebrowser/widgets/tabwidget.py b/qutebrowser/widgets/tabwidget.py index 40267384c..5a3ba90cd 100644 --- a/qutebrowser/widgets/tabwidget.py +++ b/qutebrowser/widgets/tabwidget.py @@ -24,7 +24,6 @@ from PyQt5.QtWidgets import QTabWidget, QTabBar, QSizePolicy from PyQt5.QtGui import QIcon, QPixmap import qutebrowser.config.config as config -import qutebrowser.utils.log as log from qutebrowser.config.style import set_register_stylesheet from qutebrowser.utils.style import Style @@ -108,11 +107,8 @@ class TabWidget(QTabWidget): self.setUsesScrollButtons(config.get('tabbar', 'scroll-buttons')) posstr = config.get('tabbar', 'position') selstr = config.get('tabbar', 'select-on-remove') - try: - self.setTabPosition(position_conv[posstr]) - self.tabBar().setSelectionBehaviorOnRemove(select_conv[selstr]) - except KeyError as e: - log.init.warn(e) + self.setTabPosition(position_conv[posstr]) + self.tabBar().setSelectionBehaviorOnRemove(select_conv[selstr]) @pyqtSlot(str, str) def on_config_changed(self, section, _option):