I wrote a logger that outputs stdout/stderr (info, warning, error and debug) to a Qt Window that also output’s to a logging file.
The problem that I’m having now is that I’ve broken Maya’s print statement. Print output will only show up in the Qt Window that I have re-directed output too.
How do I reset Maya’s Script Editor to starting receiving output from print statements again?
NOTE: It’s only Python’s print statement that doesn’t work, everything else outputs (i.e., mel.eval(‘print “Hello World”’)
SOLUTION:
Since I was overwriting XStream and redefining stdout I needed to reset stdout to point to Maya’s output, but where is that? Well, the hint was staring me in the face, I just needed to find it; the answer was in plogging.py (pymel’s logging system). There’s a function called _fixMayaOutput and they use it to reset their own logging system.
So…
import sys
from maya import utils
# redefine sys.stdout
sys.stdout = utils.Output
# in order to use stdout 'write' requires a 'maya.Output' so we flush it
class MayaOutput(sys.stdout):
def flush(*args, **kwargs):
utils.Output = MayaOutput()
sys.stdout = utils.Output
# initialize
log = MayaOutput()
# and flush, we're back to feeding output to the script editor
log.flush()
print("Hello World")