Hacker News new | ask | show | jobs
by drzoltar 1456 days ago
Are there any good 3rd party alternatives that work better?
3 comments

structlog
You always need some boilerplate to get structlog working. I always use this (author) to have the needed defaults https://github.com/peakiq/logma.
Yeah, it exists

But IMO it inherited most of loggers problems while not offering a better interface

It is basically a kwargs to json or 'key=value' converter

(Also json logs are overrated. There I said it. Especially one key per line, please don't)

They're quite powerful if you aggregate in a tool like Splunk, ES, or GCloud logging.

You need good quality logs though. Because noisy useless JSON logs are even more noisy and useless.

Agreed on the one key per line bit.

agreed. one key per line is straight up madness. in general, your logs should not go out of their way to break grep.
loguru perhaps
A few months ago I built a project and wanted to add logging. After searching around, I ended up selecting loguru and it definitely is a nicer user experience. But I also didn't really love it, for reasons that I don't recall now. I would look to it again, simply for lack of a better choice.

Sadly, my social media is subscribed to by pretty heavy hitters in the Python community, but when I asked about the best logging for python it was all crickets. Maybe that says something. :-)

This is the only library I that both can use out of the box and extend to my needs.
One missing feature of loguru is filter by logging levels. You can still get around it by modifying an internal variable that you can specifically not to
What do you mean? You just add a custom handler. It's like a few lines to write a handler that does some action on specific levels.
Not sure about 3rd party, but I know another built-in one.

  print(f"log_func: {var_a} not found!")
Pro tip: Try {var_a=} instead.