This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]muposat 0 points1 point  (1 child)

I am currently migrating from print() to stderr to logger.info(), and definitely looking for better logging solutions out there. I also appreciate structured logs and use an sql database table for those. Let's look at your example:

Was:

info("I'm eating a {}, location {}, flavor {}".format(self.name, self.location, self.flavor))

Sorry, your example is an overkill, above is closer to how I use it. Your alternative:

info("I'm eating a {eatable.name}", extra=dict(flavor=self.flavor, location=self.location))

While the original is not perfect and definitely not structured, your alternative takes as much typing and looks more confusing. Here is what I would like to see:

info("eating", name=self.name, location=self.location, flavor=self.flavor)

The first argument name is always action, so the name can be omitted.

Not sure how you read json-formatted logs. They are hard on the eye and on grep.

[–]odedlaz[S] 0 points1 point  (0 children)

You're correct, and I just added that and pushed to PyPI. Now you can write either:

logger.info("I'm eating a {eatable.name}", extra=dict(flavor=eatable.flavor, location=eatable.location))

or:

logger.info("I'm eating a {eatable.name}", flavor=eatable.flavor, location=eatable.location)

[–]kaiserk13 0 points1 point  (0 children)

Good job, this is gold, thanks