How do I log an exception at warning- or info-leve

2019-02-01 09:09发布

Using something like this:

try:
   # Something...
except Exception as excep:
   logger = logging.getLogger("component")
   logger.warning("something raised an exception: " + excep)
   logger.info("something raised an exception: " + excep)

I would rather not have it on the error-level cause in my special case it is not an error.

7条回答
Deceive 欺骗
2楼-- · 2019-02-01 09:46

In some cases, you might want to use the warnings library. You can have very fine-grained control over how your warnings are displayed.

查看更多
登录 后发表回答