Skip to content

Commit 1ac4f76

Browse files
committed
Add logging commands
1 parent 029c801 commit 1ac4f76

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎src/fastapi_app/app.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import logging
23
import pathlib
34
from datetime import datetime
45

@@ -12,9 +13,14 @@
1213

1314
from .models import Restaurant, Review, engine
1415

16+
logging.basicConfig(level=logging.DEBUG)
17+
1518
if os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING"):
1619
configure_azure_monitor()
1720

21+
print("Setting up FastAPI app...")
22+
logging.warning("From logging: Setting up FastAPI app...")
23+
1824
app = FastAPI()
1925
parent_path = pathlib.Path(__file__).parent.parent
2026
app.mount("/mount", StaticFiles(directory=parent_path / "static"), name="static")
@@ -23,7 +29,6 @@
2329
# Use relative path for url_for, so that it works behind a proxy like Codespaces
2430
templates.env.globals["url_for"] = app.url_path_for
2531

26-
2732
# Dependency to get the database session
2833
def get_db_session():
2934
with Session(engine) as session:
@@ -33,6 +38,7 @@ def get_db_session():
3338
@app.get("/", response_class=HTMLResponse)
3439
async def index(request: Request, session: Session = Depends(get_db_session)):
3540
print("root called")
41+
logging.warning("From logging: root called")
3642
statement = (
3743
select(Restaurant, func.avg(Review.rating).label("avg_rating"), func.count(Review.id).label("review_count"))
3844
.outerjoin(Review, Review.restaurant == Restaurant.id)

0 commit comments

Comments
 (0)