Skip to content

access_log_class can't be used in handle_args of aiohttp.web.Application #3158

Closed
@renanivo

Description

Long story short

I'm setting up a project with a custom access logger. My code looks like:

# main.py
import asyncio

from aiohttp import web
from aiohttp.abc import AbstractAccessLogger


class AccessLogger(AbstractAccessLogger):

    def log(self, request, response, time):
        self.logger.info(f'{request.remote} '
                         f'"{request.method} {request.path} '
                         f'done in {time}s: {response.status}')


loop = asyncio.get_event_loop()

app = web.Application(
    loop=loop,
    handler_args={
         'access_log_class': AccessLogger,
    },
)

When I run it with gunicorn:

gunicorn main:app --bind localhost:8080 --worker-class aiohttp.worker.GunicornWebWorker

An error is raised:

TypeError: type object got multiple values for keyword argument 'access_log_class'

Turns out handler_args overrides every keyword argument of Application.make_handler(), except access_log_class.

Expected behaviour

Using access_log_class in handler_args and my given value replace the default aiohttp.helpers.AccessLogger.

Actual behaviour

TypeError: type object got multiple values for keyword argument 'access_log_class'

Steps to reproduce

Setup a file with the contents of main.py above and run it with the gunicorn command above.

Your environment

python 3.6.6

$ pip freeze
aiohttp==3.3.2
async-timeout==3.0.0
attrs==18.1.0
chardet==3.0.4
gunicorn==19.9.0
idna==2.7
idna-ssl==1.1.0
multidict==4.3.1
yarl==1.2.6

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions