diff --git a/examples/wslook/wslook/app.py b/examples/wslook/wslook/app.py index 7e4d4248c..4db3a59ca 100644 --- a/examples/wslook/wslook/app.py +++ b/examples/wslook/wslook/app.py @@ -1,4 +1,5 @@ from datetime import datetime +import logging import uvicorn @@ -7,6 +8,12 @@ from falcon.asgi import Request from falcon.asgi import WebSocket + +logger = logging.getLogger('ws-logger') +logger.setLevel('INFO') +logger.addHandler(logging.StreamHandler()) + + REPORTS = { 'report1': { 'title': 'Report 1', @@ -39,7 +46,7 @@ async def process_resource_ws(self, req: Request, ws: WebSocket, resource, param # This will be called for the HTTP request that initiates the # WebSocket handshake after routing (if a route matches the # request). - print(f'WebSocket connection established on {req.path}') + logger.info('WebSocket connection established on %r', req.path) class AuthMiddleware: @@ -64,7 +71,7 @@ async def process_request_ws(self, req: Request, ws: WebSocket): return # Never log tokens in production - print(f'Client with token "{token}" Authenticated') + logger.info('Client with token %r Authenticated', token) class HelloWorldResource: @@ -90,7 +97,7 @@ async def on_websocket(self, req: Request, ws: WebSocket): try: query = await ws.receive_text() report = REPORTS.get(query, None) - print(report) + logger.info('selected report: %s', report) if report is None: await ws.send_media({'error': 'report not found'})