Skip to content

Commit feae9fd

Browse files
schopin-propoljar
authored andcommitted
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>
1 parent 989708d commit feae9fd

2 files changed

Lines changed: 20 additions & 27 deletions

File tree

matrix/config.py

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@
2424
Server specific configuration options are handled in server.py
2525
"""
2626

27+
import logging
2728
from builtins import super
2829
from collections import namedtuple
2930
from enum import IntEnum, Enum, unique
3031

31-
import logbook
32-
3332
import nio
3433
from matrix.globals import SCRIPT_NAME, SERVERS, W
3534
from matrix.utf import utf8_decode
@@ -57,9 +56,8 @@ class NewChannelPosition(IntEnum):
5756
NEXT = 1
5857
NEAR_SERVER = 2
5958

60-
61-
nio.logger_group.level = logbook.ERROR
62-
59+
nio_logger = logging.getLogger("nio")
60+
nio_logger.setLevel(logging.ERROR)
6361

6462
class Option(
6563
namedtuple(
@@ -141,18 +139,13 @@ def change_log_level(category, level):
141139
Called every time the user changes the log level or log category
142140
configuration option."""
143141

142+
if category == "encryption":
143+
category = "crypto"
144+
144145
if category == "all":
145-
nio.logger_group.level = level
146-
elif category == "http":
147-
nio.http.logger.level = level
148-
elif category == "client":
149-
nio.client.logger.level = level
150-
elif category == "events":
151-
nio.events.logger.level = level
152-
elif category == "responses":
153-
nio.responses.logger.level = level
154-
elif category == "encryption":
155-
nio.crypto.logger.level = level
146+
nio_logger.setLevel(level)
147+
else:
148+
nio_logger.getChild(category).setLevel(level)
156149

157150

158151
@utf8_decode
@@ -178,7 +171,7 @@ def config_log_level_cb(data, option):
178171
@utf8_decode
179172
def config_log_category_cb(data, option):
180173
"""Callback for the network.debug_category option."""
181-
change_log_level(G.CONFIG.debug_category, logbook.ERROR)
174+
change_log_level(G.CONFIG.debug_category, logging.ERROR)
182175
G.CONFIG.debug_category = G.CONFIG.network.debug_category
183176
change_log_level(
184177
G.CONFIG.network.debug_category, G.CONFIG.network.debug_level
@@ -203,20 +196,20 @@ def config_pgup_cb(data, option):
203196
return 1
204197

205198

206-
def level_to_logbook(value):
199+
def level_to_logging(value):
207200
if value == 0:
208-
return logbook.ERROR
201+
return logging.ERROR
209202
if value == 1:
210-
return logbook.WARNING
203+
return logging.WARNING
211204
if value == 2:
212-
return logbook.INFO
205+
return logging.INFO
213206
if value == 3:
214-
return logbook.DEBUG
207+
return logging.DEBUG
215208

216-
return logbook.ERROR
209+
return logging.ERROR
217210

218211

219-
def logbook_category(value):
212+
def logging_category(value):
220213
if value == 0:
221214
return "all"
222215
if value == 1:
@@ -647,7 +640,7 @@ def __init__(self):
647640
0,
648641
"error",
649642
"Enable network protocol debugging.",
650-
level_to_logbook,
643+
level_to_logging,
651644
config_log_level_cb,
652645
),
653646
Option(
@@ -658,7 +651,7 @@ def __init__(self):
658651
0,
659652
"all",
660653
"Debugging category",
661-
logbook_category,
654+
logging_category,
662655
config_log_category_cb,
663656
),
664657
Option(

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ atomicwrites
66
attrs
77
logbook
88
pygments
9-
matrix-nio[e2e]>=0.18.7
9+
matrix-nio[e2e]>=0.21.0
1010
aiohttp ; python_version >= "3.5"
1111
python-magic
1212
requests

0 commit comments

Comments
 (0)