papertrail / papertrail-cli

Command-line client for Papertrail hosted syslog & app log management service
http://papertrailapp.com/
MIT License
427 stars 46 forks source link

Python's logging with severity level is different from Heroku console's severity level #111

Open hwlee96 opened 3 years ago

hwlee96 commented 3 years ago

I'm trying to implement logging in my python (FastAPI) web app with severity levels and deploy in Heroku and Papertrail's log drain add-on. 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}"

image

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 Papertrail as well.

However, even with the python's logging config above, in Papertrail, the std output is still categorized as under INFO even though it is a WARNING log, as seen in the picture below.

image

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?