It will be easier to avoid using basicConfig()
in your case - just create the handler and add it programmatically (ensuring that the code runs just once), e.g.:
root_logger= logging.getLogger()
root_logger.setLevel(logging.DEBUG) # or whatever
handler = logging.FileHandler('test.log', 'w', 'utf-8') # or whatever
handler.setFormatter(logging.Formatter('%(name)s %(message)s')) # or whatever
root_logger.addHandler(handler)
That's more or less what basicConfig()
does.
Update: As of Python 3.9 (still in development), basicConfig()
should have encoding
and errors
keywords available.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…