Exceptional Logging of Exceptions in Python 小記

閱讀這篇 Exceptional Logging of Exceptions in Python 的紀錄。

  1. 可以這樣紀錄 exception
    logger.exception("Fatal error in main loop")
    
  2. 或是
    logger.error("Fatal error in main loop", exc_info=True)
    

Anti-pattern

不要用

try:
    something()
except Exception:
    pass

因為會什麼都捕捉不到,日後會讓你找死。不管怎麼樣,最好還是加上 logger 來紀錄

logger.exception("Fatal error in main loop")