matrix: Make logging configurable.
This commit is contained in:
parent
59b034737e
commit
4b67dc015b
3 changed files with 61 additions and 6 deletions
1
main.py
1
main.py
|
@ -455,7 +455,6 @@ if __name__ == "__main__":
|
||||||
handler = WeechatHandler()
|
handler = WeechatHandler()
|
||||||
handler.format_string = "{record.channel}: {record.message}"
|
handler.format_string = "{record.channel}: {record.message}"
|
||||||
handler.push_application()
|
handler.push_application()
|
||||||
nio.http.logger.level = logbook.DEBUG
|
|
||||||
|
|
||||||
# TODO if this fails we should abort and unload the script.
|
# TODO if this fails we should abort and unload the script.
|
||||||
matrix.globals.CONFIG = W.config_new("matrix",
|
matrix.globals.CONFIG = W.config_new("matrix",
|
||||||
|
|
|
@ -16,6 +16,9 @@
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import nio
|
||||||
|
import logbook
|
||||||
|
|
||||||
from matrix.plugin_options import (Option, RedactType, ServerBufferType)
|
from matrix.plugin_options import (Option, RedactType, ServerBufferType)
|
||||||
|
|
||||||
import matrix.globals
|
import matrix.globals
|
||||||
|
@ -30,6 +33,19 @@ def matrix_config_reload_cb(data, config_file):
|
||||||
return W.WEECHAT_RC_OK
|
return W.WEECHAT_RC_OK
|
||||||
|
|
||||||
|
|
||||||
|
def change_log_level(category, level):
|
||||||
|
if category == "all":
|
||||||
|
nio.logger_group.level = level
|
||||||
|
elif category == "http":
|
||||||
|
nio.http.logger.level = level
|
||||||
|
elif category == "client":
|
||||||
|
nio.client.logger.level = level
|
||||||
|
elif category == "events":
|
||||||
|
nio.events.logger.level = level
|
||||||
|
elif category == "responses":
|
||||||
|
nio.responses.logger.level = level
|
||||||
|
|
||||||
|
|
||||||
@utf8_decode
|
@utf8_decode
|
||||||
def matrix_config_change_cb(data, option):
|
def matrix_config_change_cb(data, option):
|
||||||
option_name = key_from_value(OPTIONS.options, option)
|
option_name = key_from_value(OPTIONS.options, option)
|
||||||
|
@ -49,6 +65,36 @@ def matrix_config_change_cb(data, option):
|
||||||
elif option_name == "max_backlog_sync_events":
|
elif option_name == "max_backlog_sync_events":
|
||||||
OPTIONS.backlog_limit = W.config_integer(option)
|
OPTIONS.backlog_limit = W.config_integer(option)
|
||||||
|
|
||||||
|
elif option_name == "debug_level":
|
||||||
|
value = W.config_integer(option)
|
||||||
|
if value == 0:
|
||||||
|
OPTIONS.debug_level = logbook.ERROR
|
||||||
|
elif value == 1:
|
||||||
|
OPTIONS.debug_level = logbook.WARNING
|
||||||
|
elif value == 2:
|
||||||
|
OPTIONS.debug_level = logbook.INFO
|
||||||
|
elif value == 3:
|
||||||
|
OPTIONS.debug_level = logbook.DEBUG
|
||||||
|
|
||||||
|
change_log_level(OPTIONS.debug_category, OPTIONS.debug_level)
|
||||||
|
|
||||||
|
elif option_name == "debug_category":
|
||||||
|
value = W.config_integer(option)
|
||||||
|
change_log_level(OPTIONS.debug_category, logbook.ERROR)
|
||||||
|
|
||||||
|
if value == 0:
|
||||||
|
OPTIONS.debug_category = "all"
|
||||||
|
elif value == 1:
|
||||||
|
OPTIONS.debug_category = "http"
|
||||||
|
elif value == 2:
|
||||||
|
OPTIONS.debug_category = "client"
|
||||||
|
elif value == 3:
|
||||||
|
OPTIONS.debug_category = "events"
|
||||||
|
elif value == 4:
|
||||||
|
OPTIONS.debug_category = "responses"
|
||||||
|
|
||||||
|
change_log_level(OPTIONS.debug_category, OPTIONS.debug_level)
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
|
@ -80,7 +126,11 @@ def matrix_config_init(config_file):
|
||||||
Option("max_backlog_sync_events", "integer", "", 1, 100, "10",
|
Option("max_backlog_sync_events", "integer", "", 1, 100, "10",
|
||||||
("How many events to fetch during backlog fetching")),
|
("How many events to fetch during backlog fetching")),
|
||||||
Option("fetch_backlog_on_pgup", "boolean", "", 0, 0, "on",
|
Option("fetch_backlog_on_pgup", "boolean", "", 0, 0, "on",
|
||||||
("Fetch messages in the backlog on a window page up event"))
|
("Fetch messages in the backlog on a window page up event")),
|
||||||
|
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")
|
||||||
]
|
]
|
||||||
|
|
||||||
def add_global_options(section, options):
|
def add_global_options(section, options):
|
||||||
|
@ -101,8 +151,8 @@ def matrix_config_init(config_file):
|
||||||
|
|
||||||
add_global_options(section, look_options)
|
add_global_options(section, look_options)
|
||||||
|
|
||||||
section = W.config_new_section(config_file, "network", 0, 0, "", "", "", "",
|
section = W.config_new_section(config_file, "network", 0, 0, "", "", "",
|
||||||
"", "", "", "", "", "")
|
"", "", "", "", "", "", "")
|
||||||
|
|
||||||
add_global_options(section, network_options)
|
add_global_options(section, network_options)
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,9 @@
|
||||||
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import logbook
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from enum import Enum, unique
|
from enum import Enum, unique
|
||||||
|
|
||||||
|
@ -49,7 +52,8 @@ class PluginOptions:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.redaction_type = RedactType.STRIKETHROUGH # type: RedactType
|
self.redaction_type = RedactType.STRIKETHROUGH # type: RedactType
|
||||||
self.look_server_buf = ServerBufferType.MERGE_CORE # type: ServerBufferType
|
self.look_server_buf = ServerBufferType.MERGE_CORE \
|
||||||
|
# type: ServerBufferType
|
||||||
|
|
||||||
self.sync_limit = 30 # type: int
|
self.sync_limit = 30 # type: int
|
||||||
self.backlog_limit = 10 # type: int
|
self.backlog_limit = 10 # type: int
|
||||||
|
@ -59,4 +63,6 @@ class PluginOptions:
|
||||||
self.redaction_comp_len = 50 # type: int
|
self.redaction_comp_len = 50 # type: int
|
||||||
|
|
||||||
self.options = dict() # type: Dict[str, weechat.config_option]
|
self.options = dict() # type: Dict[str, weechat.config_option]
|
||||||
self.debug = [] # type: List[DebugType]
|
self.debug = []
|
||||||
|
self.debug_level = logbook.ERROR
|
||||||
|
self.debug_category = "all"
|
||||||
|
|
Loading…
Reference in a new issue