1+ import logging
12import os
23import pathlib
34from datetime import datetime
1213
1314from .models import Restaurant , Review , engine
1415
16+ # Setup logger and Azure Monitor:
17+ logger = logging .getLogger ("app" )
18+ logger .setLevel (logging .INFO )
1519if os .getenv ("APPLICATIONINSIGHTS_CONNECTION_STRING" ):
1620 configure_azure_monitor ()
1721
22+
23+ # Setup FastAPI app:
1824app = FastAPI ()
1925parent_path = pathlib .Path (__file__ ).parent .parent
2026app .mount ("/mount" , StaticFiles (directory = parent_path / "static" ), name = "static" )
@@ -32,7 +38,7 @@ def get_db_session():
3238
3339@app .get ("/" , response_class = HTMLResponse )
3440async def index (request : Request , session : Session = Depends (get_db_session )):
35- print ("root called" )
41+ logger . info ("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 )
@@ -53,7 +59,7 @@ async def index(request: Request, session: Session = Depends(get_db_session)):
5359
5460@app .get ("/create" , response_class = HTMLResponse )
5561async def create_restaurant (request : Request ):
56- print ("Request for add restaurant page received" )
62+ logger . info ("Request for add restaurant page received" )
5763 return templates .TemplateResponse ("create_restaurant.html" , {"request" : request })
5864
5965
@@ -62,7 +68,7 @@ async def add_restaurant(
6268 request : Request , restaurant_name : str = Form (...), street_address : str = Form (...), description : str = Form (...),
6369 session : Session = Depends (get_db_session )
6470):
65- print ( f "name: { restaurant_name } address: { street_address } description: { description } " )
71+ logger . info ( "name: %s address: %s description: %s" , restaurant_name , street_address , description )
6672 restaurant = Restaurant ()
6773 restaurant .name = restaurant_name
6874 restaurant .street_address = street_address
0 commit comments