blog:210105_log_micropython_console_text_to_file

Log Micropython console text to file

Here is a small snippet, how you can write everything what you get on console to file in your Micropython device. This may help you to debug long running devices.

import io, os
 
class logToFile(io.IOBase):
    def __init__(self):
        pass
 
    def write(self, data):
        with open("logfile.txt", mode="a") as f:
            f.write(data)
        return len(data)
 
# now your console text output is saved into file
os.dupterm(logToFile())
 
# disable logging to file
os.dupterm(None)
Enter your comment. Wiki syntax is allowed:
If you can't read the letters on the image, download this .wav file to get them read to you.
 
  • blog/210105_log_micropython_console_text_to_file.txt
  • Last modified: 2021/04/04 00:21
  • by lixas