Emit a record. Unless record.terminator is set, a trailing
           newline will be written to the output stream.

def emit(self, record):
        """Emit a record. Unless record.terminator is set, a trailing
           newline will be written to the output stream."""
        try:
            msg = self.format(record)
            if isinstance(msg,unicode):
                if hasattr(self.stream, "encoding") and self.stream.encoding:
                    # Stream should take care of encoding, but do it explicitly to
                    # prevent bug in Python 2.6 - see
                    # https://stackoverflow.com/questions/8016236/python-unicode-handling-differences-between-print-and-sys-stdout-write
                    self.stream.write(msg.encode(self.stream.encoding))
                else:
                    self.stream.write(msg.encode(encoding))
            else:
                self.stream.write(msg)
            terminator = getattr(record, 'terminator', '\n')
            if terminator is not None:
                self.stream.write(terminator)
            self.flush()
        except (KeyboardInterrupt, SystemExit):
            raise
        except:
            self.handleError(record)