-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
31 lines (23 loc) · 899 Bytes
/
main.py
File metadata and controls
31 lines (23 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from typing import Dict, Callable
from fastapi import FastAPI, Response, Request
from datetime import datetime
from settings import LOG_LEVEL
from logging_middleware import log_request
import logging
import os
# Ensure the logs directory exists
os.makedirs('./logs', exist_ok=True)
logging.basicConfig(
level=LOG_LEVEL,
format='%(asctime)s - %(levelname)s - %(message)s',
filename=f"./logs/{datetime.now().strftime('%Y-%m-%d')}.log",
)
app = FastAPI()
@app.middleware('http')
async def request_log_middleware(request: Request, call_next: Callable) -> Response:
await log_request(request)
response: Response = await call_next(request)
return response
@app.api_route("/hello", methods = ["GET"], description="Hello World endpoint to check whether the server is running. Serving as a health check endpoint.")
async def hello_world() -> Dict[str, str]:
return {"Hello": "World"}