Repository: qutebrowser/qutebrowser

Issue:
:debug-log-filter webview crashes
```
Traceback (most recent call last):
  File "/home/miles/packages/repos/qutebrowser/qutebrowser/commands/runners.py", line 295, in run_safely
    self.run(text, count)
  File "/home/miles/packages/repos/qutebrowser/qutebrowser/commands/runners.py", line 274, in run
    result.cmd.run(self._win_id, args, count=count)
  File "/home/miles/packages/repos/qutebrowser/qutebrowser/commands/command.py", line 525, in run
    self.handler(*posargs, **kwargs)
  File "/home/miles/packages/repos/qutebrowser/qutebrowser/misc/utilcmds.py", line 290, in debug_log_filter
    log.console_filter.names = filters.split(',')
AttributeError: 'NoneType' object has no attribute 'names'
```


Discussion:
Running `:debug-log-level webview`gives me `level: Invalid value webview - expected one of: vdebug, debug, info, warning, error, critical` with 9cd2c9a. Doesn't seem to crash?

Tested in WebKit and WebEngine.
Sorry - that should be `:debug-log-filter`, not `:debug-log-level`.

Resolving patch:
diff --git a/qutebrowser/misc/utilcmds.py b/qutebrowser/misc/utilcmds.py
--- a/qutebrowser/misc/utilcmds.py
+++ b/qutebrowser/misc/utilcmds.py
@@ -293,15 +293,24 @@ def debug_log_filter(filters: str):
     """Change the log filter for console logging.
 
     Args:
-        filters: A comma separated list of logger names.
+        filters: A comma separated list of logger names. Can also be "none" to
+                 clear any existing filters.
     """
-    if set(filters.split(',')).issubset(log.LOGGER_NAMES):
-        log.console_filter.names = filters.split(',')
-    else:
+    if log.console_filter is None:
+        raise cmdexc.CommandError("No log.console_filter. Not attached "
+                                  "to a console?")
+
+    if filters.strip().lower() == 'none':
+        log.console_filter.names = None
+        return
+
+    if not set(filters.split(',')).issubset(log.LOGGER_NAMES):
         raise cmdexc.CommandError("filters: Invalid value {} - expected one "
                                   "of: {}".format(filters,
                                                   ', '.join(log.LOGGER_NAMES)))
 
+    log.console_filter.names = filters.split(',')
+
 
 @cmdutils.register()
 @cmdutils.argument('current_win_id', win_id=True)
diff --git a/qutebrowser/utils/log.py b/qutebrowser/utils/log.py
--- a/qutebrowser/utils/log.py
+++ b/qutebrowser/utils/log.py
@@ -182,9 +182,10 @@ def init_log(args):
     root = logging.getLogger()
     global console_filter
     if console is not None:
+        console_filter = LogFilter(None)
         if args.logfilter is not None:
-            console_filter = LogFilter(args.logfilter.split(','))
-            console.addFilter(console_filter)
+            console_filter.names = args.logfilter.split(',')
+        console.addFilter(console_filter)
         root.addHandler(console)
     if ram is not None:
         root.addHandler(ram)


Test patch:
diff --git a/tests/end2end/features/utilcmds.feature b/tests/end2end/features/utilcmds.feature
--- a/tests/end2end/features/utilcmds.feature
+++ b/tests/end2end/features/utilcmds.feature
@@ -164,3 +164,10 @@ Feature: Miscellaneous utility commands exposed to the user.
     Scenario: Using debug-log-filter with invalid filter
         When I run :debug-log-filter blah
         Then the error "filters: Invalid value blah - expected one of: statusbar, *" should be shown
+
+    Scenario: Using debug-log-filter
+        When I run :debug-log-filter commands,ipc,webview
+        And I run :enter-mode insert
+        And I run :debug-log-filter none
+        And I run :leave-mode
+        Then "Entering mode KeyMode.insert *" should not be logged