Last active
February 14, 2023 16:04
-
-
Save pushp1997/a998c264eeca17f2236bb28b2c54d7ca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from os import getenv | |
from fastapi import FastAPI | |
from multiprocessing import Queue | |
from logging_loki import LokiQueueHandler | |
app = FastAPI() | |
loki_logs_handler = LokiQueueHandler( | |
Queue(-1), | |
url=getenv("LOKI_ENDPOINT"), | |
tags={"application": "fastapi"}, | |
version="1", | |
) | |
uvicorn_access_logger = logging.getLogger("uvicorn.access") | |
uvicorn_access_logger.addHandler(loki_logs_handler) | |
@app.get("/") | |
async def root(): | |
return {"message": "Hello World"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment