Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing access_log_class option to aiohttp #807

Closed
lucas03 opened this issue Dec 2, 2018 · 7 comments
Closed

Passing access_log_class option to aiohttp #807

lucas03 opened this issue Dec 2, 2018 · 7 comments
Labels

Comments

@lucas03
Copy link

lucas03 commented Dec 2, 2018

Description

I wanna pass custom formatting to access logs. I could not find an option to do that.

gunicorn config:

import os
import multiprocessing

workers = multiprocessing.cpu_count() * 2 + 1
worker_class = "aiohttp.worker.GunicornUVLoopWebWorker"
proc_name = "score_machine"

bind = ":8080"
accesslog = "-"  # send access log to stdout

app.py:

def create_app():
    connexion_app = AioHttpApp(
        __name__,
        specification_dir="schema/",
        options={"swagger_ui": True},
    )
    connexion_app.add_api(
        "schema.yml",
        validate_responses=True,
        strict_validation=True,
        resolver=RestyResolver("kw.score_machine.handlers"),
    )

    return connexion_app.app


application = create_app()

custom access log class:

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}')

running server -> gunicorn kw.score_machine.app --config=.misc/gunicorn_config.py. FYI: There is related issue to access_log_class in aiohttp.

Expected behaviour

I could just put it to options as access_log_class=AccessLogger or handler_args={ 'access_log_class': AccessLogger}

Actual behaviour

I guess it's not supported?

Steps to reproduce

Additional info:

Output of the commands:

  • connexion version: 2.0.2
@lucas03 lucas03 changed the title Passing access_log_class to aiohttp Passing access_log_class option to aiohttp Dec 2, 2018
@dtkav dtkav added the question label Dec 11, 2018
@dtkav
Copy link
Collaborator

dtkav commented Dec 16, 2018

@dutradda do you know how to do this?

@pando85
Copy link
Contributor

pando85 commented Dec 17, 2018

I found in code that you can do this doing:

    app.run(port=8080, access_log=your_access_log)

@lucas03
Copy link
Author

lucas03 commented Dec 17, 2018

I saw this, but I am not running app, gunicorn is AFAIK. But I guess I did not dig deep enough here.

@pando85
Copy link
Contributor

pando85 commented Dec 17, 2018

@lucas03 Don't use gunicorn with aiohttp, from docs: running aiohttp application under gunicorn is slightly slower

Async implementation works better with python bin...

@lucas03
Copy link
Author

lucas03 commented Dec 18, 2018

running aiohttp application under gunicorn is slightly slower

If I wanna sacrifice slower app for gunicorn perks?

@pando85
Copy link
Contributor

pando85 commented Dec 18, 2018

Yea, it's your choose, sorry.

@lucas03
Copy link
Author

lucas03 commented Dec 18, 2018

OK, I'm resolving this issue. Thanks

@lucas03 lucas03 closed this as completed Dec 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants