logging.basicConfig(filename='example.log', level=logging.DEBUG, encoding='utf-8')
When I try the above code I get this error
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/logging/__init__.py", line 2009, in basicConfig
raise ValueError('Unrecognised argument(s): %s' % keys)
ValueError: Unrecognised argument(s): encoding
I tried going through the docs only to find that encoding is a valid argument for basicConfig().
Can someone explain?
From the error message, I can assume that you're using Python 3.8, which means that you should stick to the keywords that are supported by this version: filename, filemode, format, datefmt, style, level, stream, handlers, force.
The encoding keyword was added in Python 3.9
To explicitly define the encoding of a log file in Python 3.8, we can use a file handler:
log_handler = logging.FileHandler(filename='example.log', encoding='utf-8')
logging.basicConfig(handlers=[log_handler], level=logging.DEBUG)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With