'Emit a record.
If a formatter is specified, it is used to format the record.
The record is then written to the stream with a trailing newline.  If
exception information is present, it is formatted using
traceback.print_exception and appended to the stream.  If the stream
has an \'encoding\' attribute, it is used to determine how to do the
output to the stream.'

def emit(self, record):

    try:
        msg = self.format(record)
        stream = self.stream
        fs = '%s\n'
        if (not _unicode):
            stream.write((fs % msg))
        else:
            try:
                if (isinstance(msg, unicode) and getattr(stream, 'encoding', None)):
                    ufs = u'%s\n'
                    try:
                        stream.write((ufs % msg))
                    except UnicodeEncodeError:
                        stream.write((ufs % msg).encode(stream.encoding))
                else:
                    stream.write((fs % msg))
            except UnicodeError:
                stream.write((fs % msg.encode('UTF-8')))
        self.flush()
    except (KeyboardInterrupt, SystemExit):
        raise
    except:
        self.handleError(record)
