mpFileLog.py 352 B

12345678910
  1. import logging
  2. import os
  3. class MPFileLogHandler(logging.Handler):
  4. def __init__(self, file_path):
  5. self._fd = os.open(file_path, os.O_WRONLY | os.O_CREAT | os.O_APPEND)
  6. logging.Handler.__init__(self)
  7. def emit(self, record):
  8. msg = "{}\n".format(self.format(record))
  9. os.write(self._fd, msg.encode('utf-8'))