Skip to content

Commit

Permalink
readme: update imports in example
Browse files Browse the repository at this point in the history
  • Loading branch information
messa authored Jun 2, 2024
1 parent 259e89b commit 79517fb
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,29 @@ Usage
-----

```python
from aiohttp import web
from aiohttp.web import Application, Response, RouteTableDef, run_app
from aiohttp.web_log import AccessLogger
from aiohttp_request_id_logging import (
setup_logging_request_id_prefix,
request_id_middleware,
RequestIdContextAccessLogger)

routes = RouteTableDef()

@routes.get('/')
async def hello(request):
return web.Response(text="Hello, world!\n")
return Response(text="Hello, world!\n")

logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s [%(threadName)s] %(name)-26s %(levelname)5s: %(requestIdPrefix)s%(message)s')

setup_logging_request_id_prefix()

app = web.Application(middlewares=[request_id_middleware()])
app.add_routes([web.get('/', hello)])
app = Application(middlewares=[request_id_middleware()])
app.router.add_routes(routes)

web.run_app(app, access_log_class=RequestIdContextAccessLogger)
run_app(app, access_log_class=RequestIdContextAccessLogger)
```

For more complete example see [demo.py](demo.py).
Expand Down

0 comments on commit 79517fb

Please sign in to comment.