matrix: Enable nio logger.
This commit is contained in:
parent
5990704c0d
commit
3785cd0bee
1 changed files with 28 additions and 0 deletions
28
main.py
28
main.py
|
@ -31,7 +31,10 @@ from future.utils import bytes_to_native_str as n
|
||||||
|
|
||||||
# pylint: disable=unused-import
|
# pylint: disable=unused-import
|
||||||
from typing import (List, Set, Dict, Tuple, Text, Optional, AnyStr, Deque, Any)
|
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 nio import TransportType
|
||||||
|
|
||||||
from matrix.colors import Formatted
|
from matrix.colors import Formatted
|
||||||
|
@ -92,6 +95,9 @@ WEECHAT_SCRIPT_LICENSE = "ISC" # type: str
|
||||||
# yapf: enable
|
# yapf: enable
|
||||||
|
|
||||||
|
|
||||||
|
logger = Logger("matrix-cli")
|
||||||
|
|
||||||
|
|
||||||
def print_certificate_info(buff, sock, cert):
|
def print_certificate_info(buff, sock, cert):
|
||||||
cert_pem = ssl.DER_cert_to_PEM_cert(sock.getpeercert(True))
|
cert_pem = ssl.DER_cert_to_PEM_cert(sock.getpeercert(True))
|
||||||
|
|
||||||
|
@ -419,6 +425,23 @@ def autoconnect(servers):
|
||||||
server.connect()
|
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 __name__ == "__main__":
|
||||||
if W.register(WEECHAT_SCRIPT_NAME, WEECHAT_SCRIPT_AUTHOR,
|
if W.register(WEECHAT_SCRIPT_NAME, WEECHAT_SCRIPT_AUTHOR,
|
||||||
WEECHAT_SCRIPT_VERSION, WEECHAT_SCRIPT_LICENSE,
|
WEECHAT_SCRIPT_VERSION, WEECHAT_SCRIPT_LICENSE,
|
||||||
|
@ -429,6 +452,11 @@ if __name__ == "__main__":
|
||||||
"directory").format(prefix=W.prefix("error"))
|
"directory").format(prefix=W.prefix("error"))
|
||||||
W.prnt("", message)
|
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.
|
# TODO if this fails we should abort and unload the script.
|
||||||
matrix.globals.CONFIG = W.config_new("matrix",
|
matrix.globals.CONFIG = W.config_new("matrix",
|
||||||
"matrix_config_reload_cb", "")
|
"matrix_config_reload_cb", "")
|
||||||
|
|
Loading…
Add table
Reference in a new issue