Search in sources :

Example 1 with ProgressLogRecord

use of de.lmu.ifi.dbs.elki.logging.progress.ProgressLogRecord in project elki by elki-project.

the class LogPane method publish.

/**
 * Publish a log record to the logging pane.
 *
 * @param record
 *        Log record
 * @throws Exception
 */
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);
    }
}
Also used : Formatter(java.util.logging.Formatter) ErrorFormatter(de.lmu.ifi.dbs.elki.logging.ErrorFormatter) MessageFormatter(de.lmu.ifi.dbs.elki.logging.MessageFormatter) StyledDocument(javax.swing.text.StyledDocument) Style(javax.swing.text.Style) ProgressLogRecord(de.lmu.ifi.dbs.elki.logging.progress.ProgressLogRecord)

Example 2 with ProgressLogRecord

use of de.lmu.ifi.dbs.elki.logging.progress.ProgressLogRecord in project elki by elki-project.

the class LogPanel method publish.

/**
 * Publish a logging record.
 *
 * @param record Log record to publish
 */
protected void publish(final LogRecord record) {
    if (record instanceof ProgressLogRecord) {
        ProgressLogRecord preg = (ProgressLogRecord) record;
        Progress prog = preg.getProgress();
        JProgressBar pbar = getOrCreateProgressBar(prog);
        updateProgressBar(prog, pbar);
        if (prog.isComplete()) {
            removeProgressBar(prog, pbar);
        }
        if (prog.isComplete() || prog instanceof StepProgress) {
            publishTextRecord(record);
        }
    } else {
        publishTextRecord(record);
    }
}
Also used : FiniteProgress(de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress) Progress(de.lmu.ifi.dbs.elki.logging.progress.Progress) StepProgress(de.lmu.ifi.dbs.elki.logging.progress.StepProgress) MutableProgress(de.lmu.ifi.dbs.elki.logging.progress.MutableProgress) IndefiniteProgress(de.lmu.ifi.dbs.elki.logging.progress.IndefiniteProgress) JProgressBar(javax.swing.JProgressBar) ProgressLogRecord(de.lmu.ifi.dbs.elki.logging.progress.ProgressLogRecord) StepProgress(de.lmu.ifi.dbs.elki.logging.progress.StepProgress)

Example 3 with ProgressLogRecord

use of de.lmu.ifi.dbs.elki.logging.progress.ProgressLogRecord in project elki by elki-project.

the class CLISmartHandler method publish.

/**
 * Publish a log record.
 */
@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;
    }
}
Also used : Progress(de.lmu.ifi.dbs.elki.logging.progress.Progress) Formatter(java.util.logging.Formatter) ProgressLogRecord(de.lmu.ifi.dbs.elki.logging.progress.ProgressLogRecord) Writer(java.io.Writer)

Aggregations

ProgressLogRecord (de.lmu.ifi.dbs.elki.logging.progress.ProgressLogRecord)3 Progress (de.lmu.ifi.dbs.elki.logging.progress.Progress)2 Formatter (java.util.logging.Formatter)2 ErrorFormatter (de.lmu.ifi.dbs.elki.logging.ErrorFormatter)1 MessageFormatter (de.lmu.ifi.dbs.elki.logging.MessageFormatter)1 FiniteProgress (de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress)1 IndefiniteProgress (de.lmu.ifi.dbs.elki.logging.progress.IndefiniteProgress)1 MutableProgress (de.lmu.ifi.dbs.elki.logging.progress.MutableProgress)1 StepProgress (de.lmu.ifi.dbs.elki.logging.progress.StepProgress)1 Writer (java.io.Writer)1 JProgressBar (javax.swing.JProgressBar)1 Style (javax.swing.text.Style)1 StyledDocument (javax.swing.text.StyledDocument)1