I'm trying to implement logging in my python (FastAPI) web app with severity levels and deploy in Heroku. However, with python's logging module as configured below:
import logging
import sys
logging.basicConfig(
format="[%(asctime)s] %(filename)s:%(lineno)-5d %(levelname)-8s: %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
level=logging.INFO,
handlers=[
logging.StreamHandler(sys.stdout)
]
)
logger = logging.getLogger("plant-pot-backend")
@router.post('/add')
async def create(new_pot: PotHttpReq):
try:
pot_id = new_pot.id
new_pot = new_pot_registration(pot_id)
pots_collection.document(pot_id).set(new_pot.dict())
logger.warning("New pot added: {}".format(pot_id))
return {"success": True}
except Exception as e:
print(e)
return f"An Error Occured: {e}"
Specifically, I wish to get the same type of logging format, as shown in the output line with the green INFO. This allows me to filter these severity levels through log drains like Papertrail as well.
However, even with the python's logging config above, the std output is still categorized as under INFO even though it is a WARNING log, as seen in the picture.
If everything is under INFO type log in the Heroku console and logs, I can't filter them in log drains.
Any help on this?