java.lang.Object
net.i2p.util.LogRecordFormatter

class LogRecordFormatterextends Object
Render a log record according to the log manager's settings.
  • Field Details

    • NL

      static final String NL
      Line separator.
    • MAX_WHERE_LENGTH

      private static final int MAX_WHERE_LENGTH
      Max length for the source class name column.
      See Also:
    • MAX_THREAD_LENGTH

      private static final int MAX_THREAD_LENGTH
      Max length for the thread name column — 12 fits SAM-PoolWkr.9 with 1-digit suffix.
      See Also:
    • MAX_PRIORITY_LENGTH

      private static final int MAX_PRIORITY_LENGTH
      Max length for the priority label column.
      See Also:
    • SEPARATOR

      private static final String SEPARATOR
      Joins the fields of a log line.
      See Also:
    • ELLIPSIS

      private static final String ELLIPSIS
      Marks text shortened to fit the column.
      See Also:
    • BUNDLE_NAME

      private static final String BUNDLE_NAME
      Name of the bundle for the level names, deliberately not translated outside that bundle.
      See Also:
  • Constructor Details

    • LogRecordFormatter

      LogRecordFormatter()
      Constructor. Every method here is static and reads only its arguments, so an instance carries no state of its own.
  • Method Details

    • formatRecord

      public static String formatRecord(LogManager manager, LogRecord rec)
      Format a log record per manager settings.
      Parameters:
      manager - the log manager with format configuration
      rec - the log record to format
      Returns:
      the formatted log line
    • formatRecord

      static String formatRecord(LogManager manager, LogRecord rec, boolean showDate)
      Render one log record, optionally omitting the date.
      Parameters:
      manager - the log manager whose format configuration drives the layout
      rec - the log record to render, whose throwable is appended as a stack trace
      showDate - if false, skip any date in the format (use when writing to wrapper log)
      Returns:
      the formatted log line, ending in a newline
    • getThread

      private static String getThread(LogRecord logRecord)
      Format thread name to exactly MAX_THREAD_LENGTH chars, padded or truncated.
      Parameters:
      logRecord - the record whose thread name is rendered
      Returns:
      the thread name, padded with spaces or truncated to fit the column
    • getWhen

      public static String getWhen(LogManager manager, LogRecord logRecord)
      Format the record timestamp.
      Parameters:
      manager - the log manager supplying the date format, shared and therefore not thread-safe
      logRecord - the record whose date field is rendered
      Returns:
      the formatted timestamp string
    • getPriority

      private static String getPriority(LogRecord rec, I2PAppContext ctx)
      Return the localized priority label.
      Parameters:
      rec - the record whose priority level is labeled
      ctx - the context used to select the translation language
      Returns:
      the localized level name, padded or truncated to the column width
    • getWhere

      private static String getWhere(LogRecord rec)
      Format the source class name, padded or truncated to MAX_WHERE_LENGTH.
      Parameters:
      rec - the record whose source class is rendered
      Returns:
      the source class name, or "<none>" when the record has no source
    • padOrTruncate

      static String padOrTruncate(String str, int size)
      Truncate or pad to exactly size chars; if truncated, keeps the suffix and prefixes with "..." so column width stays constant.

      Used for the thread, source, and priority columns so every log line has fixed-width output regardless of the underlying name length.

      Parameters:
      str - the raw name, or null (treated as empty)
      size - the exact output width, must be > 3
      Returns:
      a string of exactly size chars: right-padded with spaces when short, or the last size - 3 chars prefixed with "…" when longer than size
    • _x

      private static String _x(String s)
      Mark a string for extraction by xgettext and translation. Use this only in static initializers. It does not translate!
      Parameters:
      s - the string to mark for extraction
      Returns:
      the string, unchanged and untranslated