The TouchInit.py module overwrites sys.stdout and sys.stderr with implementations that pipe the results to the console (StdoutCatcher using td.stdout(…), StderrCatcher using td.stderr(…)). Is there a way to access the real stdout so I can have things that print to both the TD console and the TD process’s real standard output/error?
According to the python sys module documentation, sys.stdin contains the original standard output, but my attempts to write to that don’t seem to send anything to the TD process’s output. The calls succeed and even return the correct number of bytes written, but those bytes don’t seem to go anywhere.
Even stashing the original stderr, stdout in the TouchInit.py script doesn’t seem to route anything to the console.
Did you know you can write to any DAT as well, if you are looking for logging errors?
op('text1').write('abc')
or even
sys.stdout = op('text1')
for example.
You’ll want to restore those values after logging though.
Does that help?
The goal is to have logging that can be efficiently streamed into a monitoring application and/or persisted somewhere in the case of crashes.
I could maybe use a DAT that gets dumped to a file. It could either do the output on every logged event (which would have a performance impact), or it could periodically dump to a file (which would require a timer and wouldn’t always include the most recent events when crashing).
Our approach has been to build a module that we can call at specific events, and then we usually append every event that we’re watching:
op( textop ).save( path, append = True )
This actually appends and saves the text file.