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

Backend Web App "uvicorn" logger not working #820

Open
supplemarty opened this issue Aug 15, 2024 Discussed in #818 · 5 comments
Open

Backend Web App "uvicorn" logger not working #820

supplemarty opened this issue Aug 15, 2024 Discussed in #818 · 5 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@supplemarty
Copy link

Discussed in #818

Originally posted by supplemarty August 15, 2024
The backend (and enrichment) web apps use the "uvicorn" logger as seen here:
log = logging.getLogger("uvicorn") log.setLevel('DEBUG') log.propagate = True

When I use this log variable in the backend code for debug tracing like:
log.debug("HELLO WORLD")
those log entries do not show up in the log stream NOR application insights but in the enrichment app this same pattern seems to be working fine.

I setup my own logger using the StreamHandler, and it works as I would expect. I cannot see where uvicorn is getting its logging dict configuration in the azure web app configuration. Thoughts?

@KronemeyerJoshua
Copy link
Contributor

Python apps run on Azure App Service for Linux use a gunicorn WSGI by default.
https://learn.microsoft.com/en-us/azure/app-service/configure-language-python

By default the logging and debugging arguments are not set in the terraform

appCommandLine = "gunicorn -w 4 -k uvicorn.workers.UvicornWorker app:app"

You can specify more commands in your app service where the gunicorn command is set and restart it. If you want to log them to a file you should use the access log command
https://docs.gunicorn.org/en/20.x/settings.html#accesslog
To enable debugging at a log level, you should specify it using the log level command.
https://docs.gunicorn.org/en/20.x/settings.html#accesslog

You also have the option to override this, if you wish to use uvicorn directly instead.
https://learn.microsoft.com/en-us/azure/developer/python/configure-python-web-app-on-app-service#other-frameworks-and-web-servers

@supplemarty
Copy link
Author

supplemarty commented Aug 15, 2024

Sorry if I am missing something but why does the uvicorn logger work for the enrichment app but not the backend web app?

@KronemeyerJoshua
Copy link
Contributor

Is there a specific error or statement you are not seeing that you can point to?
The backend makes use of asynchronous generators, which means logging when it happens must be proceeded by a yield statement to actually output to the log if it's inside an asynchronous generator.

I also noticed the compare and directGPT approaches do not have a logging config set, which may be a reason if it is specific to logging those approaches as a global logging level is not specified with logging.basicConfig

Logging is set at several different layers of the application, narrowing it down to a specific file or function would be helpful in debugging this.

@supplemarty
Copy link
Author

In the backend app.py you will see the log = logging.getLogger("uvicorn") as I pointed out above. The code was written to setLevel("DEBUG"). Any calls to log.debug("HELLO WORLD") fail to show any output in the log stream for the backend web app nor app insights. I used the out of the box deployment code.

@dayland dayland added the bug Something isn't working label Aug 23, 2024
@dayland
Copy link
Contributor

dayland commented Aug 29, 2024

We have added this to the backlog and assigned an engineer to review.

@dayland dayland assigned dayland and unassigned bjakems Feb 24, 2025
@dayland dayland added this to the 2.0 milestone Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants