fastapi-alembic-sqlmodel-async icon indicating copy to clipboard operation
fastapi-alembic-sqlmodel-async copied to clipboard

How to log to disk daily?

Open jymchng opened this issue 2 years ago • 4 comments

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.

jymchng avatar Apr 20 '23 16:04 jymchng

@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"}

jonra1993 avatar Apr 20 '23 23:04 jonra1993

How about storing the logs in minio?

jymchng avatar Apr 23 '23 15:04 jymchng

How about storing the logs in minio?

@jonra1993 Sir, what do you think of this?

jymchng avatar May 04 '23 16:05 jymchng

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

jonra1993 avatar Jun 01 '23 00:06 jonra1993