Hacker News new | ask | show | jobs
by teddyh 2290 days ago
> Use the almost undocumented `exc_info=True`

Why not simply use logger.exception()?

  try:
      do_thing()
  except Exception:
      logger.exception("It broke.")
Called from within an exception handler, logger.exception() automatically includes exception information.
1 comments

Mostly because I didn't know of it. But also if you want to log caught exceptions as debug, because you were expecting the exception. E.g., a StopIteration exception you for some reason might want information about, or you have an object you need to check if it has a certain key, but for some reason doesn't have a get-method.

I'm sure there are also good reasons :)