Improve logging in signal filter

This commit is contained in:
Florian Bruhin 2014-05-16 21:49:35 +02:00
parent 5c4ce7ae09
commit 19da80e58e
3 changed files with 17 additions and 6 deletions

View File

@ -70,9 +70,6 @@ class SignalFilter(QObject):
"""
sender = self.sender()
log_signal = not signal.signal.startswith('2cur_progress')
if log_signal:
logging.debug("signal {} (tab {})".format(
dbg_signal(signal, args), self._tabs.indexOf(sender)))
if not isinstance(sender, WebView):
# BUG? This should never happen, but it does regularely...
logging.warn("Got signal {} by {} which is no tab!".format(
@ -80,8 +77,10 @@ class SignalFilter(QObject):
return
if self._tabs.currentWidget() == sender:
if log_signal:
logging.debug(" emitting")
logging.debug("emitting: {} (tab {})".format(
dbg_signal(signal, args), self._tabs.indexOf(sender)))
signal.emit(*args)
else:
if log_signal:
logging.debug(" ignoring")
logging.debug("ignoring: {} (tab {})".format(
dbg_signal(signal, args), self._tabs.indexOf(sender)))

View File

@ -47,6 +47,15 @@ class TestDebug(TestCase):
self.assertEqual(sigutils.dbg_signal(self.signal, [23, 42]),
'fake(23, 42)')
def test_dbg_signal_eliding(self):
self.assertEqual(sigutils.dbg_signal(self.signal,
[12345678901234567890123]),
'fake(1234567890123456789\u2026)')
def test_dbg_signal_newline(self):
self.assertEqual(sigutils.dbg_signal(self.signal, ['foo\nbar']),
'fake(foo bar)')
if __name__ == '__main__':
unittest.main()

View File

@ -19,6 +19,8 @@
import re
from qutebrowser.utils.misc import elide
def signal_name(sig):
"""Get a cleaned up name of a signal.
@ -43,4 +45,5 @@ def dbg_signal(sig, args):
Return:
A human-readable string representation of signal/args.
"""
return '{}({})'.format(signal_name(sig), ', '.join(map(str, args)))
argstr = ', '.join([elide(str(a).replace('\n', ' '), 20) for a in args])
return '{}({})'.format(signal_name(sig), argstr)