matrix: Add option to log into a separate debug buffer.
This commit is contained in:
parent
32df9230ea
commit
df61dba644
3 changed files with 24 additions and 3 deletions
18
main.py
18
main.py
|
@ -84,7 +84,7 @@ from matrix.config import (matrix_config_init, matrix_config_read,
|
||||||
|
|
||||||
import matrix.globals
|
import matrix.globals
|
||||||
|
|
||||||
from matrix.globals import W, SERVERS, SCRIPT_NAME
|
from matrix.globals import W, SERVERS, SCRIPT_NAME, OPTIONS
|
||||||
|
|
||||||
# yapf: disable
|
# yapf: disable
|
||||||
WEECHAT_SCRIPT_NAME = SCRIPT_NAME
|
WEECHAT_SCRIPT_NAME = SCRIPT_NAME
|
||||||
|
@ -429,6 +429,11 @@ def autoconnect(servers):
|
||||||
server.connect()
|
server.connect()
|
||||||
|
|
||||||
|
|
||||||
|
def debug_buffer_close_cb(data, buffer):
|
||||||
|
OPTIONS.debug_buffer_ptr = ""
|
||||||
|
return W.WEECHAT_RC_OK
|
||||||
|
|
||||||
|
|
||||||
class WeechatHandler(StreamHandler):
|
class WeechatHandler(StreamHandler):
|
||||||
def __init__(self, level=logbook.NOTSET, format_string=None, filter=None,
|
def __init__(self, level=logbook.NOTSET, format_string=None, filter=None,
|
||||||
bubble=False):
|
bubble=False):
|
||||||
|
@ -443,7 +448,16 @@ class WeechatHandler(StreamHandler):
|
||||||
)
|
)
|
||||||
|
|
||||||
def write(self, item):
|
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__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -95,6 +95,9 @@ def matrix_config_change_cb(data, option):
|
||||||
|
|
||||||
change_log_level(OPTIONS.debug_category, OPTIONS.debug_level)
|
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":
|
elif option_name == "fetch_backlog_on_pgup":
|
||||||
OPTIONS.enable_backlog = W.config_boolean(option)
|
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,
|
Option("debug_level", "integer", "error|warn|info|debug", 0, 0,
|
||||||
"off", "Enable network protocol debugging."),
|
"off", "Enable network protocol debugging."),
|
||||||
Option("debug_category", "integer", "all|http|client|events|responses",
|
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):
|
def add_global_options(section, options):
|
||||||
|
|
|
@ -66,3 +66,5 @@ class PluginOptions:
|
||||||
self.debug = []
|
self.debug = []
|
||||||
self.debug_level = logbook.ERROR
|
self.debug_level = logbook.ERROR
|
||||||
self.debug_category = "all"
|
self.debug_category = "all"
|
||||||
|
self.debug_buffer = False
|
||||||
|
self.debug_buffer_ptr = ""
|
||||||
|
|
Loading…
Reference in a new issue