I have the following code:
#!/usr/bin/env python
import logging
import sys
import copy
class Wrapper:
def write(self, s):
#sys.__stdout__.write(s)
loggy = logging.getLogger('foobar')
loggy.info(s)
def blah():
logger = logging.getLogger('foobar')
logger.setLevel(logging.DEBUG)
streamhandle = logging.StreamHandler(sys.stdout)
streamhandle.setFormatter(logging.Formatter('[%(message)s]'))
logger.addHandler(streamhandle)
sys.stdout = Wrapper()
sys.stderr = Wrapper()
if __name__ == '__main__':
blah()
logger = logging.getLogger('')
#print logger.handlers
#for handler in logger.handlers:
# print handler
fooy = logging.getLogger('foobar')
#print fooy.handlers
sys.stdout.write('i love you')
logging.log(logging.DEBUG, 'i love you')
This code causes python to go in an infinite recursive loop, and the output is actually incredibly cool:
[Error in sys.exitfunc:
]
[INFO:foobar:Error in sys.exitfunc:
]
[INFO:foobar:INFO:foobar:Error in sys.exitfunc:
]
[INFO:foobar:INFO:foobar:INFO:foobar:Error in sys.exitfunc:
]
[INFO:foobar:INFO:foobar:INFO:foobar:INFO:foobar:Error in sys.exitfunc:
]
[INFO:foobar:INFO:foobar:INFO:foobar:INFO:foobar:INFO:foobar:Error in sys.exitfunc:
This keeps growing exponentially :) Its pretty but why is this happening?