How do I setup logging when using aiohttp and aiopg with Gunicorn?
<p><code>aiohttp</code> is great, but setting up logging has been a nightmare, both locally and in production, when using <code>Gunicorn</code>.</p>

<p>Most of the examples and documentation I find for setting up logging are for running in native server mode, where you use <code>make_handler()</code></p>

<p>As recommended in the documentation, I'm using <code>Gunicorn</code> as a Web Server to deploy, so I don't call <code>make_handler</code> explicitly. </p>

<p><strong>I am not seeing aiohttp.access logs, nor the aiohttp.server logs, nor the aiopg logs, all of which should be set up by default</strong></p>

<p>This is what I've got in a root level <code>app.py</code>:</p>

<pre><code>import logging

import aiopg
from aiohttp import web

async def some_handler(request):
    id = request.match_info["id"]
    # perform some SA query
    return web.json_response({"foo": id})

async def close_postgres(app):
    app['postgres'].close()
    await app['postgres'].wait_closed

async def init(loop, logger, config):
    app = web.Application(
        loop=loop,
        logger=logger
    )

    app['postgres'] = await aiopg.sa.create_engine(loop=loop, echo=True) # other args ommitted
    app.on_cleanup.append(close_postgres)

    app.router.add_route('GET', '/', some_handler, 'name')

    return app

def run():
    config = parse_yaml('config.yml') # =&gt; turns config.yml to dict
    logging.config.dictConfig(config['logging'])
    logger = logging.getLogger("api")

    loop = asyncio.get_event_loop()
    app = run_until_complete(init(loop, logger, config))

    return app
</code></pre>

<p>My config.yml file</p>

<pre><code>logging:
  version: 1
  formatters:
    simple:
      format: '[%(asctime)s] [%(process)d] [%(levelname)s] %(message)s'
      datefmt: '%Y-%m-%d %H:%M:%S %z'
  handlers:
    console:
      class: logging.StreamHandler
      formatter: simple
      level: DEBUG
      stream: ext://sys.stdout
  loggers:
    api:
      handlers:
        - console
      level: DEBUG
</code></pre>

<p>I launch gunicorn with the following:</p>

<pre><code>gunicorn 'app:run()' --worker-class aiohttp.worker.GunicornWebWorker
</code></pre>

<p>I only see the following logs no matter what query I make:</p>

<pre><code>[2016-08-22 11:26:46 -0400] [41993] [INFO] Starting gunicorn 19.6.0
[2016-08-22 11:26:46 -0400] [41993] [INFO] Listening at: http://127.0.0.1:8000 (41993)
[2016-08-22 11:26:46 -0400] [41993] [INFO] Using worker: aiohttp.worker.GunicornWebWorker
[2016-08-22 11:26:46 -0400] [41996] [INFO] Booting worker with pid: 41996
</code></pre>

<p>What I want:</p>

<ul>
<li>aiopg logs (which queries ran)</li>
<li>access logs</li>
<li>server logs </li>
</ul>

<p>Thanks</p>