Fix compatibility with matrix-nio 0.21

The 0.21.0 made a breaking change in how they handle logging, moving off
logbook to the standard logging module, breaking weechat-matrix's config
module.

This patch adresses the API change (without migrating ourselves to
logboox), and bumps the matrix-nio requirements to reflect the
dependency on the new API.

Signed-off-by: Simon Chopin <simon.chopin@canonical.com>
This commit is contained in:
Simon Chopin 2023-07-18 14:04:26 +02:00 committed by Damir Jelić
parent 989708d1fa
commit feae9fda26
2 changed files with 20 additions and 27 deletions

View file

@ -24,12 +24,11 @@ To add configuration options refer to MatrixConfig.
Server specific configuration options are handled in server.py Server specific configuration options are handled in server.py
""" """
import logging
from builtins import super from builtins import super
from collections import namedtuple from collections import namedtuple
from enum import IntEnum, Enum, unique from enum import IntEnum, Enum, unique
import logbook
import nio import nio
from matrix.globals import SCRIPT_NAME, SERVERS, W from matrix.globals import SCRIPT_NAME, SERVERS, W
from matrix.utf import utf8_decode from matrix.utf import utf8_decode
@ -57,9 +56,8 @@ class NewChannelPosition(IntEnum):
NEXT = 1 NEXT = 1
NEAR_SERVER = 2 NEAR_SERVER = 2
nio_logger = logging.getLogger("nio")
nio.logger_group.level = logbook.ERROR nio_logger.setLevel(logging.ERROR)
class Option( class Option(
namedtuple( namedtuple(
@ -141,18 +139,13 @@ def change_log_level(category, level):
Called every time the user changes the log level or log category Called every time the user changes the log level or log category
configuration option.""" configuration option."""
if category == "encryption":
category = "crypto"
if category == "all": if category == "all":
nio.logger_group.level = level nio_logger.setLevel(level)
elif category == "http": else:
nio.http.logger.level = level nio_logger.getChild(category).setLevel(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
elif category == "encryption":
nio.crypto.logger.level = level
@utf8_decode @utf8_decode
@ -178,7 +171,7 @@ def config_log_level_cb(data, option):
@utf8_decode @utf8_decode
def config_log_category_cb(data, option): def config_log_category_cb(data, option):
"""Callback for the network.debug_category option.""" """Callback for the network.debug_category option."""
change_log_level(G.CONFIG.debug_category, logbook.ERROR) change_log_level(G.CONFIG.debug_category, logging.ERROR)
G.CONFIG.debug_category = G.CONFIG.network.debug_category G.CONFIG.debug_category = G.CONFIG.network.debug_category
change_log_level( change_log_level(
G.CONFIG.network.debug_category, G.CONFIG.network.debug_level G.CONFIG.network.debug_category, G.CONFIG.network.debug_level
@ -203,20 +196,20 @@ def config_pgup_cb(data, option):
return 1 return 1
def level_to_logbook(value): def level_to_logging(value):
if value == 0: if value == 0:
return logbook.ERROR return logging.ERROR
if value == 1: if value == 1:
return logbook.WARNING return logging.WARNING
if value == 2: if value == 2:
return logbook.INFO return logging.INFO
if value == 3: if value == 3:
return logbook.DEBUG return logging.DEBUG
return logbook.ERROR return logging.ERROR
def logbook_category(value): def logging_category(value):
if value == 0: if value == 0:
return "all" return "all"
if value == 1: if value == 1:
@ -647,7 +640,7 @@ class MatrixConfig(WeechatConfig):
0, 0,
"error", "error",
"Enable network protocol debugging.", "Enable network protocol debugging.",
level_to_logbook, level_to_logging,
config_log_level_cb, config_log_level_cb,
), ),
Option( Option(
@ -658,7 +651,7 @@ class MatrixConfig(WeechatConfig):
0, 0,
"all", "all",
"Debugging category", "Debugging category",
logbook_category, logging_category,
config_log_category_cb, config_log_category_cb,
), ),
Option( Option(

View file

@ -6,7 +6,7 @@ atomicwrites
attrs attrs
logbook logbook
pygments pygments
matrix-nio[e2e]>=0.18.7 matrix-nio[e2e]>=0.21.0
aiohttp ; python_version >= "3.5" aiohttp ; python_version >= "3.5"
python-magic python-magic
requests requests