/**
   * Formats the given record with the head and tail.
   *
   * @param h the Handler or null.
   * @param reset true if the summary statistics and LogRecord should be reset back to initial
   *     values.
   * @return the formatted string.
   * @see #getTail(java.util.logging.Handler)
   */
  private String formatRecord(final Handler h, final boolean reset) {
    final LogRecord record;
    final long c;
    final long t;
    long msl;
    long msh;
    synchronized (this) {
      record = last;
      c = count;
      t = thrown;
      msl = minMillis;
      msh = maxMillis;

      if (reset) { // BUG ID 6351685
        reset();
      }
    }

    if (c == 0L) { // Use the estimated lifespan of this class.
      msl = INIT_TIME;
      msh = System.currentTimeMillis();
    }

    final String head;
    final String msg;
    final String tail;
    final Formatter f = this.formatter;
    if (f != null) {
      synchronized (f) {
        head = f.getHead(h);
        msg = record != null ? f.format(record) : "";
        tail = f.getTail(h);
      }
    } else {
      head = msg = tail = "";
    }

    Locale l = null;
    if (record != null) {
      ResourceBundle rb = record.getResourceBundle();
      l = rb == null ? null : rb.getLocale();
    }

    final MessageFormat mf;
    if (l == null) { // BUG ID 8039165
      mf = new MessageFormat(fmt);
    } else {
      mf = new MessageFormat(fmt, l);
    }

    /** These arguments are described in the getTail documentation. */
    return mf.format(
        new Object[] {finish(head), finish(msg), finish(tail), c, (c - 1), t, (c - t), msl, msh});
  }
Beispiel #2
0
 @Nullable
 protected String getMessageI18N(@Nonnull LogRecord record) {
   String message = record.getMessage();
   if (message != null) {
     final ResourceBundle bundle = record.getResourceBundle();
     if (bundle != null) {
       try {
         message = bundle.getString(message);
       } catch (final MissingResourceException ignored) {
       }
     }
     final Object[] params = record.getParameters();
     if (params != null && params.length > 0) {
       message = MessageFormat.format(message, params);
     }
   }
   return message;
 }