How do I add an encoding parameter to logging.basicConfig?
I have found this bug report that states that this is now possible for Python 3.3. I need this for Python 2.7 and the bug report says to use a custom logging.FileHandler object, but I can’t get it to work.
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.:That’s more or less what
basicConfig()does.Update: In Python 3.9 and later versions,
basicConfig()hasencodinganderrorskeyword parameters available.