docs: protected synchronized void publish(LogRecord record) throws BadLocationException {
      // choose an appropriate formatter
      final Formatter fmt;
      final Style style;
      // always format progress messages using the progress formatter.
      if(record.getLevel().intValue() >= Level.WARNING.intValue()) {
        // format errors using the error formatter
        fmt = errformat;
        style = errStyle;
      }
      else if(record.getLevel().intValue() <= Level.FINE.intValue()) {
        // format debug statements using the debug formatter.
        fmt = debugformat;
        style = dbgStyle;
      }
      else {
        // default to the message formatter.
        fmt = msgformat;
        style = msgStyle;
      }
      // format
      final String m;
      m = fmt.format(record);
      StyledDocument doc = getStyledDocument();
      if(record instanceof ProgressLogRecord) {
        if(lastNewlinePos < doc.getLength()) {
          doc.remove(lastNewlinePos, doc.getLength() - lastNewlinePos);
        }
      }
      else {
        // insert a newline, if we didn't see one yet.
        if(lastNewlinePos < doc.getLength()) {
          doc.insertString(doc.getLength(), "\n", style);
          lastNewlinePos = doc.getLength();
        }
      }
      int tail = tailingNonNewline(m, 0, m.length());
      int headlen = m.length() - tail;
      if(headlen > 0) {
        String pre = m.substring(0, headlen);
        doc.insertString(doc.getLength(), pre, style);
      }
      lastNewlinePos = doc.getLength();
      if(tail > 0) {
        String post = m.substring(m.length() - tail);
        doc.insertString(lastNewlinePos, post, style);
      }
    }