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

Allow for response time logging in access logs #1366

Closed
2 tasks done
KaranTrivedi opened this issue Feb 9, 2022 · 1 comment
Closed
2 tasks done

Allow for response time logging in access logs #1366

KaranTrivedi opened this issue Feb 9, 2022 · 1 comment

Comments

@KaranTrivedi
Copy link

KaranTrivedi commented Feb 9, 2022

Checklist

  • There are no similar issues or pull requests for this yet.
  • I discussed this idea on the community chat and feedback is positive.

Is your feature related to a problem? Please describe.

I am able to log user requests in the access logs, but not able to track response times.

Describe the solution you would like.

I hope the access logs allows for a pattern that lets user to define pattern in logger to capture response time

Current:

"access": {
            "()": "uvicorn.logging.AccessFormatter",
            "datefmt": "%Y-%m-%dT%H:%M:%S%z",
            "fmt": '%(asctime)s::%(levelprefix)s %(client_addr)s - "%(request_line)s" %(status_code)s',
            "use_colors": False,
        },

Future:

"access": {
            "()": "uvicorn.logging.AccessFormatter",
            "datefmt": "%Y-%m-%dT%H:%M:%S%z",
            "fmt": '%(asctime)s::%(levelprefix)s %(client_addr)s - "%(request_line)s" **%(resp_time)s** %(status_code)s',
            "use_colors": False,
        },

Describe alternatives you considered

I was suggested third party tool in the community chat:
https://github.com/steinnes/timing-asgi

Seems like an improper solution for this. The response time is not embedded in the access log itself...

Sample log from library git page..

INFO: Started server process [35895]
INFO: Waiting for application startup.
2019-03-07 11:38:01 INFO  [timing_asgi.middleware:44] ASGI scope of type lifespan is not supported yet
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: ('127.0.0.1', 58668) - "GET / HTTP/1.1" 200
myapp.__main__.homepage 0.0006690025329589844 ['http_status:200', 'http_method:GET', 'time:wall']
myapp.__main__.homepage 0.0006950000000000012 ['http_status:200', 'http_method:GET', 'time:cpu']
INFO: ('127.0.0.1', 58684) - "GET /asdf HTTP/1.1" 404
myapp.asdf 0.0005478858947753906 ['http_status:404', 'http_method:GET', 'time:wall']
myapp.asdf 0.0005909999999999804 ['http_status:404', 'http_method:GET', 'time:cpu']

Additional context

No response

@Kludex
Copy link
Sponsor Member

Kludex commented Feb 9, 2022

Duplicated #527

@Kludex Kludex closed this as completed Feb 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants