from fastapi import FastAPI
import logging
import os

app = FastAPI()


LOG_FILE = "./log/api-server.log"
CONTAINER_NAME = os.environ.get("CONTAINER_NAME", "Unknown")


@app.get("/")
async def root():
    logging.info(f"Container {CONTAINER_NAME} received request")
    return {
        "message": f"Hello World from {CONTAINER_NAME}",
    }


def main():
    logging.basicConfig(
        filename=LOG_FILE,
        format="%(asctime)s %(levelname)s %(message)s",
        level=logging.INFO,
    )
    logging.info(f"Starting server {CONTAINER_NAME}")


main()
