Example usage for java.util.logging LogRecord getMillis

List of usage examples for java.util.logging LogRecord getMillis

Introduction

In this page you can find the example usage for java.util.logging LogRecord getMillis.

Prototype

public long getMillis() 

Source Link

Document

Get truncated event time in milliseconds since 1970.

Usage

From source file:hudson.logging.LogRecorderManager.java

/**
 * Renders the given log recorders as RSS.
 *//* w  w w.j a  v  a  2 s  .  co m*/
/*package*/ static void doRss(StaplerRequest req, StaplerResponse rsp, List<LogRecord> logs)
        throws IOException, ServletException {
    // filter log records based on the log level
    String level = req.getParameter("level");
    if (level != null) {
        Level threshold = Level.parse(level);
        List<LogRecord> filtered = new ArrayList<LogRecord>();
        for (LogRecord r : logs) {
            if (r.getLevel().intValue() >= threshold.intValue())
                filtered.add(r);
        }
        logs = filtered;
    }

    RSS.forwardToRss("Hudson log", "", logs, new FeedAdapter<LogRecord>() {
        public String getEntryTitle(LogRecord entry) {
            return entry.getMessage();
        }

        public String getEntryUrl(LogRecord entry) {
            return "log"; // TODO: one URL for one log entry?
        }

        public String getEntryID(LogRecord entry) {
            return String.valueOf(entry.getSequenceNumber());
        }

        public String getEntryDescription(LogRecord entry) {
            return Functions.printLogRecord(entry);
        }

        public Calendar getEntryTimestamp(LogRecord entry) {
            GregorianCalendar cal = new GregorianCalendar();
            cal.setTimeInMillis(entry.getMillis());
            return cal;
        }

        public String getEntryAuthor(LogRecord entry) {
            return Mailer.descriptor().getAdminAddress();
        }
    }, req, rsp);
}

From source file:HTMLFormatter.java

public String format(LogRecord record) {
    return ("<tr><td>" + (new Date(record.getMillis())).toString() + "</td><td>" + record.getMessage()
            + "</td></tr>\n");
}

From source file:com.p000ison.dev.simpleclans2.dataserver.ServerLoggerHandler.java

@Override
public Formatter getFormatter() {
    return new Formatter() {

        @Override//from w ww.ja  v a2  s.c  o  m
        public String format(LogRecord record) {
            String message = DATE_FORMAT.format(record.getMillis()) + " [" + record.getLevel().toString() + "] "
                    + record.getMessage() + "\n";
            if (record.getThrown() != null) {
                message += ExceptionUtils.getStackTrace(record.getThrown()) + '\n';
            }
            return message;
        }
    };
}

From source file:ch.jamiete.hilda.LogFormat.java

@Override
public String format(final LogRecord record) {
    String log = "";

    log += this.sdf.format(new Date(record.getMillis()));
    log += " [" + record.getLevel().getLocalizedName().toUpperCase() + "]";

    if (record.getSourceClassName() != null) {
        final String[] split = record.getSourceClassName().split("\\.");
        log += " [" + split[split.length == 1 ? 0 : split.length - 1] + "]";
    }//w ww . ja  v  a 2  s.  c  o m

    log += " " + record.getMessage();

    if (record.getThrown() != null) {
        log += System.getProperty("line.separator") + ExceptionUtils.getStackTrace(record.getThrown());
    }

    log += System.getProperty("line.separator");

    return log;
}

From source file:joachimeichborn.geotag.logging.LongLogFormat.java

@Override
public String format(final LogRecord aRecord) {
    final StringBuilder sb = new StringBuilder();
    sb.append(new DateTime(aRecord.getMillis()).toString());
    sb.append(" [").append(aRecord.getLevel().getName().charAt(0)).append("] ");
    sb.append(aRecord.getMessage());//from   www .  java2 s.co m
    sb.append(" <").append(aRecord.getLoggerName()).append(">");
    sb.append(System.lineSeparator());
    if (aRecord.getThrown() != null) {
        sb.append(ExceptionUtils.getStackTrace(aRecord.getThrown()));
    }
    return sb.toString();
}

From source file:ch.jamiete.hilda.music.MusicLogFormat.java

@Override
public final String format(final LogRecord record) {
    String log = "";

    log += this.sdf.format(new Date(record.getMillis()));
    log += " [" + record.getLevel().getLocalizedName().toUpperCase() + ']';

    if (record.getSourceClassName() != null) {
        final String[] split = record.getSourceClassName().split("\\.");
        log += " [" + split[(split.length == 1) ? 0 : (split.length - 1)] + ']';
    }/*from ww  w . jav a 2s  .co  m*/

    if (record.getSourceMethodName() != null) {
        log += " (" + record.getSourceMethodName() + ')';
    }

    log += ' ' + record.getMessage();

    if (record.getThrown() != null) {
        /*log += "\n" + record.getThrown().getMessage();
                
        for (StackTraceElement element : record.getThrown().getStackTrace()) {
        log += "\n" + element.toString();
        }*/
        log += '\n' + ExceptionUtils.getStackTrace(record.getThrown());
    }

    log += System.getProperty("line.separator");

    return log;
}

From source file:at.bitfire.davdroid.log.PlainTextFormatter.java

@Override
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public String format(LogRecord r) {
    StringBuilder builder = new StringBuilder();

    if (!logcat)//from  w ww  .  j a va 2  s  .  c  om
        builder.append(DateFormatUtils.format(r.getMillis(), "yyyy-MM-dd HH:mm:ss")).append(" ")
                .append(r.getThreadID()).append(" ");

    builder.append(String.format("[%s] %s", shortClassName(r.getSourceClassName()), r.getMessage()));

    if (r.getThrown() != null)
        builder.append("\nEXCEPTION ").append(ExceptionUtils.getStackTrace(r.getThrown()));

    if (r.getParameters() != null) {
        int idx = 1;
        for (Object param : r.getParameters())
            builder.append("\n\tPARAMETER #").append(idx++).append(" = ").append(param);
    }

    if (!logcat)
        builder.append("\n");

    return builder.toString();
}

From source file:io.stallion.services.LogFormatter.java

@Override
public String format(LogRecord record) {
    StringBuilder sb = new StringBuilder();
    SimpleDateFormat df = new SimpleDateFormat("MMM dd HH:mm:ss");

    String dateString = df.format(new Date(record.getMillis()));
    String classAndMethod = record.getSourceClassName() + "." + record.getSourceMethodName() + " ";
    classAndMethod = StringUtils.rightPad(classAndMethod, 50);
    sb.append(dateString).append(" ").append(record.getLevel().getLocalizedName()).append(" ")
            .append(classAndMethod).append(formatMessage(record)).append(LINE_SEPARATOR);

    if (record.getThrown() != null) {
        try {//from w ww  .java  2 s .co m
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            record.getThrown().printStackTrace(pw);
            pw.close();
            sb.append(sw.toString());
        } catch (Exception ex) {
            // ignore
        }
    }

    return sb.toString();
}

From source file:com.cloudbees.jenkins.support.SupportLogFormatter.java

@Override
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = {
        "DE_MIGHT_IGNORE" }, justification = "The exception wasn't thrown on our stack frame")
public String format(LogRecord record) {
    StringBuilder builder = new StringBuilder();
    builder.append(fdf.format(new Date(record.getMillis())));
    builder.append(" [id=").append(record.getThreadID()).append("]");

    builder.append("\t").append(record.getLevel().getName()).append("\t");

    if (record.getSourceMethodName() != null) {
        String sourceClass;/*from   w  w  w. j  av a  2 s. c  o  m*/
        if (record.getSourceClassName() == null) {
            sourceClass = record.getLoggerName();
        } else {
            sourceClass = record.getSourceClassName();
        }

        builder.append(abbreviateClassName(sourceClass, 32)).append("#").append(record.getSourceMethodName());
    } else {
        String sourceClass;
        if (record.getSourceClassName() == null) {
            sourceClass = record.getLoggerName();
        } else {
            sourceClass = record.getSourceClassName();
        }
        builder.append(abbreviateClassName(sourceClass, 40));
    }

    builder.append(": ").append(formatMessage(record));

    if (record.getThrown() != null) {
        try {
            StringWriter writer = new StringWriter();
            PrintWriter out = new PrintWriter(writer);
            record.getThrown().printStackTrace(out);
            out.close();
            builder.append(writer.toString());
        } catch (Exception e) {
            // ignore
        }
    }

    builder.append("\n");
    return builder.toString();
}

From source file:com.acuityph.commons.logging.SimpleFormatter.java

/**
 * {@inheritDoc}/*from   w  w  w  .jav a  2s.c  om*/
 *
 * @see java.util.logging.Formatter#format(java.util.logging.LogRecord)
 */
@Override
public final String format(final LogRecord logRecord) {
    final StringBuilder sb = new StringBuilder();
    sb.append(LEVELS_MAP.get(logRecord.getLevel()));
    final DateFormat sdf = DateFormat.getDateTimeInstance();
    sb.append(sdf.format(new Date(logRecord.getMillis()))).append(' ');
    sb.append(getShortName(logRecord.getSourceClassName()));
    sb.append('.').append(logRecord.getSourceMethodName()).append(": ");
    sb.append(logRecord.getMessage()).append("\n");
    return sb.toString();
}