java.lang.Object
net.i2p.util.LogRecordFormatter
Render a log record according to the log manager's settings.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringName of the bundle for the level names, deliberately not translated outside that bundle.private static final StringMarks text shortened to fit the column.private static final PatternAnchor close tag stripped from messages in the LogManager.MESSAGE format.private static final PatternAnchor open tag stripped from messages in the LogManager.MESSAGE format.private static final intMax length for the priority label column.private static final intMax length for the thread name column — 12 fits SAM-PoolWkr.9 with 1-digit suffix.private static final intMax length for the source class name column.(package private) static final StringLine separator.private static final StringJoins the fields of a log line.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionprivate static StringMark a string for extraction by xgettext and translation.static StringformatRecord(LogManager manager, LogRecord rec) Format a log record per manager settings.(package private) static StringformatRecord(LogManager manager, LogRecord rec, boolean showDate) Render one log record, optionally omitting the date.private static StringgetPriority(LogRecord rec, I2PAppContext ctx) Return the localized priority label.private static StringFormat thread name to exactly MAX_THREAD_LENGTH chars, padded or truncated.static StringgetWhen(LogManager manager, LogRecord logRecord) Format the record timestamp.private static StringFormat the source class name, padded or truncated to MAX_WHERE_LENGTH.(package private) static StringpadOrTruncate(String str, int size) Truncate or pad to exactlysizechars; if truncated, keeps the suffix and prefixes with "..." so column width stays constant.
Field Details
NL
Line separator.MAX_WHERE_LENGTH
private static final int MAX_WHERE_LENGTHMax length for the source class name column.- See Also:
MAX_THREAD_LENGTH
private static final int MAX_THREAD_LENGTHMax 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_LENGTHMax length for the priority label column.- See Also:
SEPARATOR
ELLIPSIS
Marks text shortened to fit the column.- See Also:
LINK_OPEN
Anchor open tag stripped from messages in the LogManager.MESSAGE format.LINK_CLOSE
Anchor close tag stripped from messages in the LogManager.MESSAGE format.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
Format a log record per manager settings.- Parameters:
manager- the log manager with format configurationrec- the log record to format- Returns:
- the formatted log line
formatRecord
Render one log record, optionally omitting the date.- Parameters:
manager- the log manager whose format configuration drives the layoutrec- the log record to render, whose throwable is appended as a stack traceshowDate- if false, skip any date in the format (use when writing to wrapper log)- Returns:
- the formatted log line, ending in a newline
getThread
getWhen
Format the record timestamp.- Parameters:
manager- the log manager supplying the date format, shared and therefore not thread-safelogRecord- the record whose date field is rendered- Returns:
- the formatted timestamp string
getPriority
Return the localized priority label.- Parameters:
rec- the record whose priority level is labeledctx- the context used to select the translation language- Returns:
- the localized level name, padded or truncated to the column width
getWhere
padOrTruncate
Truncate or pad to exactlysizechars; 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
sizechars: right-padded with spaces when short, or the lastsize - 3chars prefixed with "…" when longer thansize
_x