diff --git a/main.py b/main.py index 765043a..91838b6 100644 --- a/main.py +++ b/main.py @@ -29,6 +29,7 @@ if os.path.exists(activate_this): exec(open(activate_this).read(), {'__file__': activate_this}) +import logging import socket import ssl import textwrap @@ -38,11 +39,9 @@ # pylint: disable=unused-import from typing import Any, AnyStr, Deque, Dict, List, Optional, Set, Text, Tuple -import logbook import json import OpenSSL.crypto as crypto from future.utils import bytes_to_native_str as n -from logbook import Logger, StreamHandler try: from json.decoder import JSONDecodeError @@ -114,7 +113,7 @@ # yapf: enable -logger = Logger("matrix-cli") +logger = logging.getLogger(__name__) def print_certificate_info(buff, sock, cert): @@ -532,20 +531,8 @@ def server_buffer_cb(server_name, buffer, input_data): return W.WEECHAT_RC_OK -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): +class WeechatHandler(logging.StreamHandler): + def emit(self, record): buf = "" if G.CONFIG.network.debug_buffer: @@ -555,7 +542,7 @@ def write(self, item): buf = G.CONFIG.debug_buffer - W.prnt(buf, item) + W.prnt(buf, record) def buffer_switch_cb(_, _signal, buffer_ptr): @@ -688,8 +675,7 @@ def buffer_command_cb(data, _, command): W.prnt("", message) handler = WeechatHandler() - handler.format_string = "{record.channel}: {record.message}" - handler.push_application() + logger.addHandler(handler) # TODO if this fails we should abort and unload the script. G.CONFIG = MatrixConfig() diff --git a/matrix/globals.py b/matrix/globals.py index c3e099e..22a8837 100644 --- a/matrix/globals.py +++ b/matrix/globals.py @@ -16,9 +16,9 @@ from __future__ import unicode_literals +import logging import sys from typing import Any, Dict, Optional -from logbook import Logger from collections import OrderedDict from .utf import WeechatWrapper @@ -44,5 +44,5 @@ SCRIPT_NAME = "matrix" # type: str BUFFER_NAME_PREFIX = "{}.".format(SCRIPT_NAME) # type: str TYPING_NOTICE_TIMEOUT = 4000 # 4 seconds typing notice lifetime -LOGGER = Logger("weechat-matrix") +LOGGER = logging.getLogger(__name__) UPLOADS = OrderedDict() # type: Dict[str, Upload] diff --git a/pyproject.toml b/pyproject.toml index 709adf1..2cd2ca1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,6 @@ webcolors = "^1.11.1" atomicwrites = "^1.3.0" future = { version = "^0.18.2", python = "<3.2" } attrs = "^19.3.0" -logbook = "^1.5.3" pygments = "^2.6.1" matrix-nio = { version = "^0.18.7", extras = [ "e2e" ] } python-magic = { version = "^0.4.15", optional = true }