jonra1993 / fastapi-alembic-sqlmodel-async

This is a project template which uses FastAPI, Pydantic 2.0, Alembic and async SQLModel as ORM. It shows a complete async CRUD using authentication and role base access control.
MIT License
878 stars 142 forks source link

How to log to disk daily? #64

Open jymchng opened 1 year ago

jymchng commented 1 year ago

Hi @jonra1993,

I am using logger = logging.getLogger(__name__) to do my logging at DEBUG level.

How do I dump these logs daily to disk? Thank you.

jonra1993 commented 1 year ago

@jymchng I think you should do something like this

import logging

from fastapi import FastAPI

app = FastAPI()

logger = logging.getLogger(__name__)
log_handler = logging.FileHandler(filename="app.log")
logger.addHandler(log_handler)

@app.get("/")
async def root():
    logger.info("Received request at root endpoint")
    return {"message": "Hello World"}
jymchng commented 1 year ago

How about storing the logs in minio?

jymchng commented 1 year ago

How about storing the logs in minio?

@jonra1993 Sir, what do you think of this?

jonra1993 commented 1 year ago

Hello @jymchng I do not think any reason why it should not work I I am going to add it to todo list.