fileHandler = logging.handlers.RotatingFileHandler('file.log', mode='a',
    maxBytes=10000, backupCount=5)
logger = logging.getLogger('netmap')
if LOG_TO_FILE:
    logger.addHandler(fileHandler)
Logging in Python with Config File - Using handlers defined in file through code