@Override
  public void publish(final LogRecord record) {
    // determine destination
    final Writer destination;
    if(record.getLevel().intValue() >= Level.WARNING.intValue()) {
      destination = this.err;
    }
    else {
      destination = this.out;
    }

    // format
    final String m;

    // Progress records are handled specially.
    if(record instanceof ProgressLogRecord) {
      ProgressLogRecord prec = (ProgressLogRecord) record;
      ptrack.addProgress(prec.getProgress());

      Collection<Progress> completed = ptrack.removeCompleted();
      Collection<Progress> progresses = ptrack.getProgresses();

      StringBuilder buf = new StringBuilder();
      if(!completed.isEmpty()) {
        buf.append(OutputStreamLogger.CARRIAGE_RETURN);
        for(Progress prog : completed) {
          // TODO: use formatter, somehow?
          prog.appendToBuffer(buf);
          buf.append(OutputStreamLogger.NEWLINE);
        }
      }
      if(!progresses.isEmpty()) {
        boolean first = true;
        buf.append(OutputStreamLogger.CARRIAGE_RETURN);
        for(Progress prog : progresses) {
          if(first) {
            first = false;
          }
          else {
            buf.append(' ');
          }
          // TODO: use formatter, somehow?
          prog.appendToBuffer(buf);
        }
      }
      m = buf.toString();
    }
    else {
      // choose an appropriate formatter
      final Formatter fmt;
      // always format progress messages using the progress formatter.
      if(record.getLevel().intValue() >= Level.WARNING.intValue()) {
        // format errors using the error formatter
        fmt = errformat;
      }
      else if(record.getLevel().intValue() <= Level.FINE.intValue()) {
        // format debug statements using the debug formatter.
        fmt = debugformat;
      }
      else {
        // default to the message formatter.
        fmt = msgformat;
      }
      try {
        m = fmt.format(record);
      }
      catch(Exception ex) {
        reportError(null, ex, ErrorManager.FORMAT_FAILURE);
        return;
      }
    }
    // write
    try {
      destination.write(m);
      // always flush (although the streams should auto-flush already)
      destination.flush();
    }
    catch(Exception ex) {
      reportError(null, ex, ErrorManager.WRITE_FAILURE);
      return;
    }
  }
@ Override public void publish ( final LogRecord record ) { final Writer destination ; if ( record . getLevel ( ) . intValue ( ) >= Level . WARNING . intValue ( ) ) { destination = this . err ; } else { destination = this . out ; } final String m ; if ( record instanceof ProgressLogRecord ) { ProgressLogRecord prec = ( ProgressLogRecord ) record ; ptrack . addProgress ( prec . getProgress ( ) ) ; Collection < Progress > completed = ptrack . removeCompleted ( ) ; Collection < Progress > progresses = ptrack . getProgresses ( ) ; StringBuilder buf = new StringBuilder ( ) ; if ( ! completed . isEmpty ( ) ) { buf . append ( OutputStreamLogger . CARRIAGE_RETURN ) ; for ( Progress prog : completed ) { prog . appendToBuffer ( buf ) ; buf . append ( OutputStreamLogger . NEWLINE ) ; } } if ( ! progresses . isEmpty ( ) ) { boolean first = true ; buf . append ( OutputStreamLogger . CARRIAGE_RETURN ) ; for ( Progress prog : progresses ) { if ( first ) { first = false ; } else { buf . append ( ' ' ) ; } prog . appendToBuffer ( buf ) ; } } m = buf . toString ( ) ; } else { final Formatter fmt ; if ( record . getLevel ( ) . intValue ( ) >= Level . WARNING . intValue ( ) ) { fmt = errformat ; } else if ( record . getLevel ( ) . intValue ( ) <= Level . FINE . intValue ( ) ) { fmt = debugformat ; } else { fmt = msgformat ; } try { m = fmt . format ( record ) ; } catch ( Exception ex ) { reportError ( null , ex , ErrorManager . FORMAT_FAILURE ) ; return ; } } try { destination . write ( m ) ; destination . flush ( ) ; } catch ( Exception ex ) { reportError ( null , ex , ErrorManager . WRITE_FAILURE ) ; return ; } }
Publish a log record.