class Tee(object):
    _instance = None

def __init__(self, logger):
    self.stdout = sys.stdout
self.logger = logger
sys.stdout = self

def __new__(cls, *args, **kwargs):
    if not cls._instance:
        cls._instance = super(Tee, cls).__new__(cls, *args, **kwargs)
return cls._instance

def __del__(self):
    sys.stdout = self.stdout

def write(self, data):
    data = data.rstrip('\r\n')
if data:
    self.logger.info(data)
Python: Logging module for print statements: Duplicate log entries