matrix: Enable nio logger.

This commit is contained in:
Damir Jelić 2018-07-21 19:54:36 +02:00
parent 5990704c0d
commit 3785cd0bee

28
main.py
View file

@ -31,7 +31,10 @@ from future.utils import bytes_to_native_str as n
# pylint: disable=unused-import
from typing import (List, Set, Dict, Tuple, Text, Optional, AnyStr, Deque, Any)
import logbook
from logbook import Logger, StderrHandler, StreamHandler
import nio
from nio import TransportType
from matrix.colors import Formatted
@ -92,6 +95,9 @@ WEECHAT_SCRIPT_LICENSE = "ISC" # type: str
# yapf: enable
logger = Logger("matrix-cli")
def print_certificate_info(buff, sock, cert):
cert_pem = ssl.DER_cert_to_PEM_cert(sock.getpeercert(True))
@ -419,6 +425,23 @@ def autoconnect(servers):
server.connect()
class WeechatHandler(StreamHandler):
def __init__(self, level=logbook.NOTSET, format_string=None, filter=None,
bubble=False):
StreamHandler.__init__(
self,
object(),
level,
format_string,
None,
filter,
bubble
)
def write(self, item):
W.prnt("", item)
if __name__ == "__main__":
if W.register(WEECHAT_SCRIPT_NAME, WEECHAT_SCRIPT_AUTHOR,
WEECHAT_SCRIPT_VERSION, WEECHAT_SCRIPT_LICENSE,
@ -429,6 +452,11 @@ if __name__ == "__main__":
"directory").format(prefix=W.prefix("error"))
W.prnt("", message)
handler = WeechatHandler()
handler.format_string = "{record.channel}: {record.message}"
handler.push_application()
nio.http.logger.level = logbook.DEBUG
# TODO if this fails we should abort and unload the script.
matrix.globals.CONFIG = W.config_new("matrix",
"matrix_config_reload_cb", "")