Logging traceback details in production environment

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
p_j
Posts: 102
Joined: Mon Aug 23, 2021 1:08 pm
Location: Sydney

Logging traceback details in production environment

Post by p_j » Wed Jan 26, 2022 11:49 am

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()

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: Logging traceback details in production environment

Post by davef » Wed Jan 26, 2022 5:57 pm


KJM
Posts: 158
Joined: Sun Nov 18, 2018 10:53 pm
Location: Sydney AU

Re: Logging traceback details in production environment

Post by KJM » Wed Jan 26, 2022 11:39 pm

from uio import StringIO; s=StringIO(); sys.print_exception(e, s); s=s.getvalue()

p_j
Posts: 102
Joined: Mon Aug 23, 2021 1:08 pm
Location: Sydney

Re: Logging traceback details in production environment

Post by p_j » Thu Jan 27, 2022 12:12 am

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!

Post Reply