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

Instructions to overwrite uvicorn logger #6

Open
Kludex opened this issue Nov 7, 2021 · 3 comments
Open

Instructions to overwrite uvicorn logger #6

Kludex opened this issue Nov 7, 2021 · 3 comments

Comments

@Kludex
Copy link
Owner

Kludex commented Nov 7, 2021

No description provided.

@meoyawn
Copy link

meoyawn commented Jul 29, 2022

much needed, can't really understand how to use this with blacksheep + uvicorn

@elukey
Copy link

elukey commented Apr 26, 2023

@Kludex hi! I am trying to use this nice library with KServe in kserve/kserve#2782

I am using the following snippet inside KServe's logic to override the Uvicorns access log:

        if access_log_format:
            from asgi_logger import AccessLoggerMiddleware
            # As indicated by the asgi-logger docs, we need to clear/unset
            # any setting for uvicorn.access to avoid log duplicates.
            logging.getLogger("uvicorn.access").handlers = []
            app.add_middleware(
                AccessLoggerMiddleware, format=access_log_format)
            # The asgi-logger settings don't set propagate to False,
            # so we get duplicates if we don't set it explicitly.
            logging.getLogger("access").propagate = False

I need to explicitly set logging.getLogger("access").propagate = False to avoid log duplicates, for example:

127.0.0.1:41344 - - [25/Apr/2023:16:46:57 +0000] "POST /v1/models/test:predict HTTP/1.1" 200 - "-" "curl/7.74.0"
2023-04-25 16:46:57.906 5395 access INFO [log():67] 127.0.0.1:41344 - - [25/Apr/2023:16:46:57 +0000] "POST /v1/models/test:predict HTTP/1.1" 200 - "-" "curl/7.74.0"

The above logs are generated if I don't explicitly set the propagate field. The latter seems to be generated by the log function of middleware.py, so I thought to explicitly set it in AccessLoggerMiddleware logic but when I try to run make test I see a lot of failures. Do you have any suggestion about what's best and/or if I am missing something important?

Thanks in advance!

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

4 participants
@elukey @meoyawn @Kludex and others