1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
From feae9fda26ea9de98da9cd6733980a203115537e Mon Sep 17 00:00:00 2001
From: Simon Chopin <simon.chopin@canonical.com>
Date: Tue, 18 Jul 2023 14:04:26 +0200
Subject: [PATCH] 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>
---
matrix/config.py | 45 +++++++++++++++++++--------------------------
requirements.txt | 2 +-
2 files changed, 20 insertions(+), 27 deletions(-)
diff --git a/matrix/config.py b/matrix/config.py
index f4ff40a..33063e9 100644
--- a/matrix/config.py
+++ b/matrix/config.py
@@ -24,12 +24,11 @@
Server specific configuration options are handled in server.py
"""
+import logging
from builtins import super
from collections import namedtuple
from enum import IntEnum, Enum, unique
-import logbook
-
import nio
from matrix.globals import SCRIPT_NAME, SERVERS, W
from matrix.utf import utf8_decode
@@ -57,9 +56,8 @@ class NewChannelPosition(IntEnum):
NEXT = 1
NEAR_SERVER = 2
-
-nio.logger_group.level = logbook.ERROR
-
+nio_logger = logging.getLogger("nio")
+nio_logger.setLevel(logging.ERROR)
class Option(
namedtuple(
@@ -141,18 +139,13 @@ def change_log_level(category, level):
Called every time the user changes the log level or log category
configuration option."""
+ if category == "encryption":
+ category = "crypto"
+
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
- elif category == "encryption":
- nio.crypto.logger.level = level
+ nio_logger.setLevel(level)
+ else:
+ nio_logger.getChild(category).setLevel(level)
@utf8_decode
@@ -178,7 +171,7 @@ def config_log_level_cb(data, option):
@utf8_decode
def config_log_category_cb(data, 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
change_log_level(
G.CONFIG.network.debug_category, G.CONFIG.network.debug_level
@@ -203,20 +196,20 @@ def config_pgup_cb(data, option):
return 1
-def level_to_logbook(value):
+def level_to_logging(value):
if value == 0:
- return logbook.ERROR
+ return logging.ERROR
if value == 1:
- return logbook.WARNING
+ return logging.WARNING
if value == 2:
- return logbook.INFO
+ return logging.INFO
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:
return "all"
if value == 1:
@@ -647,7 +640,7 @@ def __init__(self):
0,
"error",
"Enable network protocol debugging.",
- level_to_logbook,
+ level_to_logging,
config_log_level_cb,
),
Option(
@@ -658,7 +651,7 @@ def __init__(self):
0,
"all",
"Debugging category",
- logbook_category,
+ logging_category,
config_log_category_cb,
),
Option(
|