Websockets 在某种程度上限制了日志记录中的输出内容量。目前我算了一下,字符数限制在70个字符。门槛可以提高吗?
我需要查看完整的消息。但我在输出中得到“...”:
代码示例:
服务器.py
#!/usr/bin/env python
import logging
import asyncio
from websockets.server import serve
logging.basicConfig(format="%(asctime)s %(message)s", level=logging.DEBUG)
async def echo(websocket):
async for message in websocket:
await websocket.send(message)
async def main():
async with serve(echo, "127.0.0.1", 9954):
await asyncio.Future()
asyncio.run(main())
客户端.py
#!/usr/bin/env python
import logging
import json
from websockets.sync.client import connect
logging.basicConfig(format="%(asctime)s %(message)s", level=logging.DEBUG)
with connect("ws://127.0.0.1:9954") as websocket:
websocket.send(json.dumps({"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA@": "@BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"}))
message = websocket.recv()
print(f"Received: {message}")
我想我已经找到解决方案了。
评论即可
if len(data) > 75:
data = data[:48] + "..." + data[-24:]
在
websockets/frames.py
中
__str__
类的 Frame
方法中