How do I log an exception at warning- or info-level with traceback using the python logging framework? -
using this:
try: # something... except exception excep: logger = logging.getlogger("component") logger.warning("something raised exception: " + excep) logger.info("something raised exception: " + excep)
i rather not have on error-level cause in special case not error.
from logging documentation:
there 3 keyword arguments in
kwargs
inspected:exc_info
,stack_info
, ,extra
.if
exc_info
not evaluate false, causes exception information added logging message. if exception tuple (in format returnedsys.exc_info()
) or exception instance provided, used; otherwise,sys.exc_info()
called exception information.
so do:
logger.warning("something raised exception:", exc_info=true)
Comments
Post a Comment