def initLogging(filename):
    global logger
if logger == None:
    logger = logging.getLogger()
else:
    for handler in logger.handlers[:]:
        logger.removeHandler(handler)
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter(fmt='%(asctime)s: %(message)s', datefmt=
    '%I:%M:%S')
fh = logging.FileHandler(filename)
fh.setFormatter(formatter)
logger.addHandler(fh)
sh = logging.StreamHandler(sys.stdout)
sh.setFormatter(formatter)
logger.addHandler(sh)
Restart logging to a new file (Python)