Skip to content

Commit de2f451

Browse files
authored
Update README.md with logging info (#610)
* Update README.md with logging info * Build logging in with env var
1 parent 583b562 commit de2f451

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

README.md

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ The repo includes sample data so it's ready to try end to end. In this sample ap
5252
* **Azure subscription with access enabled for the Azure OpenAI service**. You can request access with [this form](https://aka.ms/oaiapply).
5353
* **Azure account permissions**: Your Azure account must have `Microsoft.Authorization/roleAssignments/write` permissions, such as [Role Based Access Control Administrator](https://learn.microsoft.com/azure/role-based-access-control/built-in-roles#role-based-access-control-administrator-preview), [User Access Administrator](https://learn.microsoft.com/azure/role-based-access-control/built-in-roles#user-access-administrator), or [Owner](https://learn.microsoft.com/azure/role-based-access-control/built-in-roles#owner).
5454

55-
## Azure deployment
55+
## Azure deployment
5656

5757
### Cost estimation
5858

@@ -73,7 +73,7 @@ either by deleting the resource group in the Portal or running `azd down`.
7373

7474
### Project setup
7575

76-
You have a few options for setting up this project.
76+
You have a few options for setting up this project.
7777
The easiest way to get started is GitHub Codespaces, since it will setup all the tools for you,
7878
but you can also [set it up locally](#local-environment) if desired.
7979

@@ -299,6 +299,37 @@ The ask tab uses the approach programmed in [retrievethenread.py](https://github
299299
There are also two other /ask approaches with a slightly different approach, but they aren't currently working due to [langchain compatibility issues](https://github.com/Azure-Samples/azure-search-openai-demo/issues/541).
300300
</details>
301301

302+
<details>
303+
<summary>How can we view logs from the App Service app?</summary>
304+
305+
You can view production logs in the Portal using either the Log stream or by downloading the default_docker.log file from Advanced tools.
306+
307+
The following line of code in `app/backend/app.py` configures the logging level:
308+
309+
```python
310+
logging.basicConfig(level=os.getenv("APP_LOG_LEVEL", "ERROR"))
311+
```
312+
313+
To change the default level, you can set the `APP_LOG_LEVEL` environment variable locally or in App Service
314+
to one of the [allowed log levels](https://docs.python.org/3/library/logging.html#logging-levels):
315+
`DEBUG`, `INFO`, `WARNING`, `ERROR`, `CRITICAL`.
316+
317+
If you need to log in a route handler, use the the global variable `current_app`'s logger:
318+
319+
```python
320+
async def chat_stream():
321+
current_app.logger.info("Received /chat request")
322+
```
323+
324+
Otherwise, use the `logging` module's root logger:
325+
326+
```python
327+
logging.info("System message: %s", system_message)
328+
```
329+
330+
If you're having troubles finding the logs in App Service, see this blog post on [tips for debugging App Service app deployments](http://blog.pamelafox.org/2023/06/tips-for-debugging-flask-deployments-to.html) or watch [this video about viewing App Service logs](https://www.youtube.com/watch?v=f0-aYuvws54).
331+
332+
</details>
302333

303334
### Troubleshooting
304335

@@ -314,5 +345,4 @@ Here are the most common failure scenarios and solutions:
314345

315346
1. You see `CERTIFICATE_VERIFY_FAILED` when the `prepdocs.py` script runs. That's typically due to incorrect SSL certificates setup on your machine. Try the suggestions in this [StackOverflow answer](https://stackoverflow.com/questions/35569042/ssl-certificate-verify-failed-with-python3/43855394#43855394).
316347

317-
1. After running `azd up` and visiting the website, you see a '404 Not Found' in the browser. Wait 10 minutes and try again, as it might be still starting up. Then try running `azd deploy` and wait again. If you still encounter errors with the deployed app, consult these [tips for debugging App Service app deployments](http://blog.pamelafox.org/2023/06/tips-for-debugging-flask-deployments-to.html)
318-
and file an issue if the error logs don't help you resolve the issue.
348+
1. After running `azd up` and visiting the website, you see a '404 Not Found' in the browser. Wait 10 minutes and try again, as it might be still starting up. Then try running `azd deploy` and wait again. If you still encounter errors with the deployed app, consult these [tips for debugging App Service app deployments](http://blog.pamelafox.org/2023/06/tips-for-debugging-flask-deployments-to.html) or watch [this video about downloading App Service logs](https://www.youtube.com/watch?v=f0-aYuvws54). Please file an issue if the logs don't help you resolve the error.

app/backend/app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,5 +228,6 @@ def create_app():
228228
app = Quart(__name__)
229229
app.register_blueprint(bp)
230230
app.asgi_app = OpenTelemetryMiddleware(app.asgi_app)
231-
231+
# Level should be one of https://docs.python.org/3/library/logging.html#logging-levels
232+
logging.basicConfig(level=os.getenv("APP_LOG_LEVEL", "ERROR"))
232233
return app

0 commit comments

Comments
 (0)