Class OneLineFormatter
java.lang.Object
java.util.logging.Formatter
org.apache.juli.OneLineFormatter
- Direct Known Subclasses:
JsonFormatter
Provides same information as default log format but on a single line to make it easier to grep the logs. The only
exception is stacktraces which are always preceded by whitespace to make it simple to skip them.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a OneLineFormatter with the default time format from the log manager properties. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddTimestamp(StringBuilder buf, long timestamp) Adds a formatted timestamp to the given buffer.protected static StringgetThreadName(int logRecordThreadId) LogRecord has threadID but no thread name.Obtain the format currently being used for time stamps in log messages.protected StringresolveThreadName(LogRecord record) Resolves the thread name for a log record, handling async handler cases.voidsetTimeFormat(String timeFormat) Specify the time format to use for time stamps in log messages.Methods inherited from class Formatter
formatMessage, getHead, getTail
-
Constructor Details
-
OneLineFormatter
public OneLineFormatter()Constructs a OneLineFormatter with the default time format from the log manager properties.
-
-
Method Details
-
setTimeFormat
Specify the time format to use for time stamps in log messages.- Parameters:
timeFormat- The format to use using theSimpleDateFormatsyntax
-
getTimeFormat
Obtain the format currently being used for time stamps in log messages.- Returns:
- The current format in
SimpleDateFormatsyntax
-
format
-
resolveThreadName
-
addTimestamp
Adds a formatted timestamp to the given buffer.- Parameters:
buf- The string builder to append totimestamp- The timestamp in milliseconds
-
getThreadName
LogRecord has threadID but no thread name. LogRecord uses an int for thread ID but thread IDs are longs. If the real thread ID > (Integer.MAXVALUE / 2) LogRecord uses it's own ID in an effort to avoid clashes due to overflow.Words fail me to describe what I think of the design decision to use an int in LogRecord for a long value and the resulting mess that follows.
- Parameters:
logRecordThreadId- the thread id- Returns:
- the thread name
-