I\'m using aiohttp 2 with Python 3.6 and want to log the requests coming to the application.
I did:
# use ISO timestamps
from time import gmtime
logging.
You can see my sample:
import asyncio
import logging
from aiohttp import web
mylogger = logging.getLogger('aiohttp.access')
mylogger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
mylogger.addHandler(ch)
async def handle(request):
name = request.match_info.get('name', "Anonymous")
text = "Hello, " + name
return web.Response(text=text)
loop = asyncio.get_event_loop()
app = web.Application(loop=loop)
app.router.add_get('/', handle)
app.router.add_get('/{name}', handle)
loop.run_until_complete(
loop.create_server(
app.make_handler(access_log=mylogger,
access_log_format='%r %s %b'), '0.0.0.0', 8080))
loop.run_forever()
loop.close()
run it and access 'http://127.0.0.1:8080/xmwd', you will see GET /xmwd HTTP/1.1 200 11
in your console.