Capturing console messages to a log
-
I want to capture all console output such as debug messages and uncaught exceptions to a log file. I created the following code but it's not working. It does grab the console as expected. Also, if I comment out dupterm I can console.write("Some string") and it gets added to the log. But if I raise an exception it just quits the script without adding anything to the log. Please assist.
import time from os import dupterm from uio import StringIO from _thread import start_new_thread def log_console(): console = StringIO() dupterm(console) while True: logH = open('/flash/console.log', 'w+') logH.write(console.getvalue()) logH.close() time.sleep(1) start_new_thread(log_console, ())Edit: Oops, this question is almost a duplicate. Forgot that I had asked.
-
@BetterAuto: Did you find a working solution? I'm hitting the same problem.
-
Afraid not.
-
Check out
sys.print_exception, that might be able to help with printing out exceptions and traceback -
@fsergeys same problem here :-(
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login