Mayil-AI-Sandbox / loguru-Jan2023

MIT License
0 stars 0 forks source link

Question: how to log exception objects (hashtag589) #118

Closed vikramsubramanian closed 2 months ago

vikramsubramanian commented 2 months ago

I have exception objects that I have obtained outside of an exception handler. I would like to log these with their tracebacks, but it's not clear if this is possible.

logger.exception does not apply here since this is not an exception handler context.

vikramsubramanian commented 2 months ago

Hi. You can probably use [opt()]( to do that:

logger.opt(exception=exc_object).error("Error message")
vikramsubramanian commented 2 months ago

That did the trick. Thanks!