diff --git a/main.py b/main.py index 381bfd1..1b0aa1a 100644 --- a/main.py +++ b/main.py @@ -84,7 +84,7 @@ from matrix.config import (matrix_config_init, matrix_config_read, import matrix.globals -from matrix.globals import W, SERVERS, SCRIPT_NAME +from matrix.globals import W, SERVERS, SCRIPT_NAME, OPTIONS # yapf: disable WEECHAT_SCRIPT_NAME = SCRIPT_NAME @@ -429,6 +429,11 @@ def autoconnect(servers): server.connect() +def debug_buffer_close_cb(data, buffer): + OPTIONS.debug_buffer_ptr = "" + return W.WEECHAT_RC_OK + + class WeechatHandler(StreamHandler): def __init__(self, level=logbook.NOTSET, format_string=None, filter=None, bubble=False): @@ -443,7 +448,16 @@ class WeechatHandler(StreamHandler): ) def write(self, item): - W.prnt("", item) + buf = "" + + if OPTIONS.debug_buffer: + if not OPTIONS.debug_buffer_ptr: + OPTIONS.debug_buffer_ptr = W.buffer_new( + "Matrix Debug", "", "", "debug_buffer_close_cb", "") + + buf = OPTIONS.debug_buffer_ptr + + W.prnt(buf, item) if __name__ == "__main__": diff --git a/matrix/config.py b/matrix/config.py index e259d75..7c49e66 100644 --- a/matrix/config.py +++ b/matrix/config.py @@ -95,6 +95,9 @@ def matrix_config_change_cb(data, option): change_log_level(OPTIONS.debug_category, OPTIONS.debug_level) + elif option_name == "debug_buffer": + OPTIONS.debug_buffer = W.config_boolean(option) + elif option_name == "fetch_backlog_on_pgup": OPTIONS.enable_backlog = W.config_boolean(option) @@ -130,7 +133,9 @@ def matrix_config_init(config_file): Option("debug_level", "integer", "error|warn|info|debug", 0, 0, "off", "Enable network protocol debugging."), Option("debug_category", "integer", "all|http|client|events|responses", - 0, 0, "all", "Debugging category") + 0, 0, "all", "Debugging category"), + Option("debug_buffer", "boolean", "", 0, 0, "off", + ("Use a separate buffer for debug logs.")), ] def add_global_options(section, options): diff --git a/matrix/plugin_options.py b/matrix/plugin_options.py index a872a85..7fbd9a6 100644 --- a/matrix/plugin_options.py +++ b/matrix/plugin_options.py @@ -66,3 +66,5 @@ class PluginOptions: self.debug = [] self.debug_level = logbook.ERROR self.debug_category = "all" + self.debug_buffer = False + self.debug_buffer_ptr = ""