From d25e1fde04ed1f6e5943367a63ac8f26e591372d Mon Sep 17 00:00:00 2001 From: knaggita Date: Wed, 3 Aug 2016 20:18:51 +0300 Subject: [PATCH] Add :debug-log-capacity command --- qutebrowser/misc/utilcmds.py | 13 +++++++++++++ qutebrowser/utils/log.py | 3 +++ 2 files changed, 16 insertions(+) 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):