lycenok
New Contributor II

Probably it's worth to try to rewrite the emit ... https://docs.python.org/3/library/logging.html#handlers

This works for me:

class OurFileHandler(logging.FileHandler):

 def emit(self, record):
   # copied from https://github.com/python/cpython/blob/master/Lib/logging/__init__.p
   if self.stream is None:
     self.stream = self._open()
   try:
     msg = self.format(record)
     stream = self.stream
     # issue 35046: merged two stream.writes into one.
     stream.write(msg + self.terminator)
     self.flush()
   except RecursionError:  # See issue 36272
     raise
   except Exception:
     self.handleError(record)


# logger must be defined 
ch = logging.FileHandler(log_file_path)
ch = OurFileHandler(log_file_path)
formatter = logging.Formatter(
    '%(asctime)s: %(name)s (%(levelname)s): %(message)s'
)
ch.setFormatter(formatter)
logger.addHandler(ch)