I have a logging script with set formatting. It is using utf-8 symbols for readability, the encoding is set for saving of the files, as seen below.
log = logging.getLogger('general')
fmt = logging.Formatter('%(asctime)s.%(msecs)03d │ %(levelname)-10s│ %(lineno)4s %(funcName)-20s│ %(message)s',
datefmt='%Y/%m/%d │ %H:%M:%S')
handler_error = logging.handlers.RotatingFileHandler("error.log", 'a', encoding="utf-8")
handler_error.setLevel(logging.INFO)
handler_error.setFormatter(fmt)
log.addHandler(handler_error)
Theoretically, all the separators should be │'s, but the one in datefmt it is being changed into ¦. Thus, the resulting log looks like below - notice all the vertical lines added properly except the one set between date and time.
I have tried using unicode \u2502 instead of │, did not help. Any ideas on how to fix this?
Edit - an error log from another user's execution.
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\logging\__init__.py", line 1025, in emit
msg = self.format(record)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\logging\__init__.py", line 869, in format
return fmt.format(record)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\logging\__init__.py", line 610, in format
record.asctime = self.formatTime(record, self.datefmt)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\logging\__init__.py", line 548, in formatTime
s = time.strftime(datefmt, ct)
UnicodeEncodeError: 'locale' codec can't encode character '\u2502' in position 9: encoding error
