Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hwlee96 opened this issue Jul 13, 2021 · 0 comments

Comments

@hwlee96
Copy link

hwlee96 commented Jul 13, 2021

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant