diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 7c4df4655..089fd23a6 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -26,6 +26,8 @@ Added `unix-filename-rubout`. - New `fonts -> completion.category` setting to customize the font used for completion category headers. +- New `:debug-log-capacity` command to adjust how many lines are logged into RAM + (to report bugs which are difficult to reproduce). Changed ~~~~~~~ diff --git a/README.asciidoc b/README.asciidoc index 68a62714c..882301381 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -220,6 +220,7 @@ Contributors, sorted by the number of commits in descending order: * zwarag * xd1le * oniondreams +* knaggita * issue * haxwithaxe * evan diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index eb384ffae..f43be5822 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -1400,6 +1400,7 @@ These commands are mainly intended for debugging. They are hidden if qutebrowser |<>|Show the debugging console. |<>|Crash for debugging purposes. |<>|Dump the current page's content to a file. +|<>|Change the number of log lines to be stored in RAM. |<>|Evaluate a python string and display the results as a web page. |<>|Put data into the fake clipboard and enable logging, used for tests. |<>|Trace executed code via hunter. @@ -1442,6 +1443,15 @@ Dump the current page's content to a file. ==== optional arguments * +*-p*+, +*--plain*+: Write plain text instead of HTML. +[[debug-log-capacity]] +=== debug-log-capacity +Syntax: +:debug-log-capacity 'capacity'+ + +Change the number of log lines to be stored in RAM. + +==== positional arguments +* +'capacity'+: Number of lines for the log. + [[debug-pyeval]] === debug-pyeval Syntax: +:debug-pyeval [*--quiet*] 's'+ diff --git a/qutebrowser/misc/utilcmds.py b/qutebrowser/misc/utilcmds.py index e1d7c6a61..fe9f580b7 100644 --- a/qutebrowser/misc/utilcmds.py +++ b/qutebrowser/misc/utilcmds.py @@ -234,3 +234,16 @@ def repeat_command(win_id, count=None): cmd = runners.last_command[mode_manager.mode] commandrunner = runners.CommandRunner(win_id) commandrunner.run(cmd[0], count if count is not None else cmd[1]) + + +@cmdutils.register(debug=True, name='debug-log-capacity') +def log_capacity(capacity: int): + """Change the number of log lines to be stored in RAM. + + Args: + capacity: Number of lines for the log. + """ + if capacity < 0: + raise cmdexc.CommandError("Can't set a negative log capacity!") + else: + log.ram_handler.change_log_capacity(capacity) diff --git a/qutebrowser/utils/log.py b/qutebrowser/utils/log.py index a377ead57..177c263f8 100644 --- a/qutebrowser/utils/log.py +++ b/qutebrowser/utils/log.py @@ -511,6 +511,9 @@ class RAMHandler(logging.Handler): lines.append(fmt(record)) return '\n'.join(lines) + def change_log_capacity(self, capacity): + self._data = collections.deque(self._data, maxlen=capacity) + class ColoredFormatter(logging.Formatter): diff --git a/tests/end2end/features/misc.feature b/tests/end2end/features/misc.feature index 1519e1867..686f5a8b4 100644 --- a/tests/end2end/features/misc.feature +++ b/tests/end2end/features/misc.feature @@ -442,6 +442,15 @@ Feature: Various utility commands. Then qute://log?level=error should be loaded And the page should contain the plaintext "No messages to show." + Scenario: Using :debug-log-capacity + When I run :debug-log-capacity 100 + And I run :message-info oldstuff + And I run :repeat 10 :message-info otherstuff + And I run :message-info newstuff + And I open qute:log + Then the page should contain the plaintext "newstuff" + And the page should not contain the plaintext "oldstuff" + ## https://github.com/The-Compiler/qutebrowser/issues/1523 Scenario: Completing a single option argument