Page 1 of 1

Logging traceback details in production environment

Posted: Wed Jan 26, 2022 11:49 am
by p_j
Hi all,

What is the best way to catch error details on production devices?

I'm using a try/catch on the outer most part of my code and then recording the exception to a file using logger. This works ok but it doesn't tell me where the error occurs, file/line number so it can be tricky to debug sometimes Is there a way to catch the full traceback?

Thanks

Code: Select all

    
    try:
        main_prog()

    except Exception as e:

        logger.error(str(e))
        logger.error("Resetting microcontroller")
        time.sleep(5)
        machine.reset()

Re: Logging traceback details in production environment

Posted: Wed Jan 26, 2022 5:57 pm
by davef

Re: Logging traceback details in production environment

Posted: Wed Jan 26, 2022 11:39 pm
by KJM
from uio import StringIO; s=StringIO(); sys.print_exception(e, s); s=s.getvalue()

Re: Logging traceback details in production environment

Posted: Thu Jan 27, 2022 12:12 am
by p_j
KJM wrote:
Wed Jan 26, 2022 11:39 pm
from uio import StringIO; s=StringIO(); sys.print_exception(e, s); s=s.getvalue()
Perfect thank you!