def write(self, data):
        """
        Write some data to the file.

        @param data: The data to write.  Text will be encoded as UTF-8.
        @type data: L{bytes} or L{unicode}
        """
        if self.shouldRotate():
            self.flush()
            self.rotate()
        if isinstance(data, unicode):
            data = data.encode('utf8')
        self._file.write(data)

        Write some data to the file.

        @param data: The data to write.  Text will be encoded as UTF-8.
        @type data: L{bytes} or L{unicode}
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/logfile.py