From 00fc46890e5b606d16665a45c8104df21fef6459 Mon Sep 17 00:00:00 2001 From: Pedro Ferreira Date: Mon, 31 Jul 2017 23:17:59 +0200 Subject: [PATCH] Add logging to test_server, fix it --- test_client.py | 6 +++--- test_server.py | 35 ++++++++++++++++++++++------------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/test_client.py b/test_client.py index 69fb9ed..151a44c 100644 --- a/test_client.py +++ b/test_client.py @@ -75,11 +75,11 @@ logger.setLevel(logging.DEBUG) logger.addHandler(ch) server_pub_key = b64decode(config['public'][:-8]) -# server_prv_key = b64decode(config['private'][:-8]) -# sign = SigningKey(server_prv_key[:32]) +server_prv_key = b64decode(config['private'][:-8]) +sign = SigningKey(server_prv_key[:32]) loop = get_event_loop() -packet_stream = PSClient('127.0.0.1', 8008, SigningKey.generate(), server_pub_key, loop=loop) +packet_stream = PSClient('127.0.0.1', 8008, sign, server_pub_key, loop=loop) packet_stream.connect() api.add_connection(packet_stream) diff --git a/test_server.py b/test_server.py index d039687..e002fd8 100644 --- a/test_server.py +++ b/test_server.py @@ -1,8 +1,10 @@ +import logging import os -from asyncio import get_event_loop +from asyncio import get_event_loop, ensure_future from base64 import b64decode import yaml +from colorlog import ColoredFormatter from nacl.signing import SigningKey from ssb.packet_stream import PSServer @@ -12,18 +14,25 @@ with open(os.path.expanduser('~/.ssb/secret')) as f: config = yaml.load(f) -async def on_connect(server): - server.write('JSON', { - "name": ["createHistoryStream"], - "args": [{ - "id": "@/Odg52x38pt7OivNnxK1Lm+H/+x6yV4DhMeXHBQRYc0=.ed25519", - "seq": 9, - "live": True, - "keys": False - }], - "type": "source"}, req=1) - print(await server.read()) - server.write('JSON', {}) +async def on_connect(): + loop.create_task(ensure_future(packet_stream)) + +# create console handler and set level to debug +ch = logging.StreamHandler() +ch.setLevel(logging.DEBUG) + +# create formatter +formatter = ColoredFormatter('%(log_color)s%(levelname)s%(reset)s:%(bold_white)s%(name)s%(reset)s - ' + '%(cyan)s%(message)s%(reset)s') + +# add formatter to ch +ch.setFormatter(formatter) + +# add ch to logger +logger = logging.getLogger('packet_stream') +logger.setLevel(logging.DEBUG) +logger.addHandler(ch) + loop = get_event_loop()