Class LogEntryFormatter
java.lang.Object
java.util.logging.Formatter
org.apache.juneau.microservice.logging.LogEntryFormatter
Log entry formatter.
Uses three simple parameter for configuring log entry formats:
-
dateFormat - ASimpleDateFormatstring describing the format for dates. -
format - A string with{...} replacement variables representing predefined fields. -
useStackTraceHashes - A setting that causes duplicate stack traces to be replaced with 8-character hash strings.
This class converts the format strings into a regular expression that can be used to parse the resulting log file.
-
Constructor Summary
ConstructorsConstructorDescriptionLogEntryFormatter(String format, String dateFormat, boolean useStackTraceHashes) Create a new formatter. -
Method Summary
Modifier and TypeMethodDescriptionReturns theDateFormatused for matching dates.Given a matcher that has matched the pattern specified bygetLogEntryPattern(), returns the field value from the match.Returns the regular expression pattern used for matching log entries.Methods inherited from class java.util.logging.Formatter
formatMessage, getHead, getTail
-
Constructor Details
-
LogEntryFormatter
Create a new formatter.- Parameters:
format- The log entry format. e.g."[{date} {level}] {msg}%n" The string can contain any of the following variables:"{date}" - The date, formatted per"Logging/dateFormat" ."{class}" - The class name."{method}" - The method name."{logger}" - The logger name."{level}" - The log level name."{msg}" - The log message."{threadid}" - The thread ID."{exception}" - The localized exception message."{traceId}" - The active OpenTelemetry trace ID (empty when OTel is absent or no span is active)."{spanId}" - The active OpenTelemetry span ID (empty when OTel is absent or no span is active).
null .dateFormat- TheSimpleDateFormatformat to use for dates. e.g."yyyy.MM.dd hh:mm:ss" .
Must not benull .useStackTraceHashes- Iftrue , only print unique stack traces once and then refer to them by a simple 8 character hash identifier.
-
-
Method Details
-
format
-
getDateFormat
Returns theDateFormatused for matching dates.Returns a defensive
clonebecauseSimpleDateFormatis mutable and not thread-safe; each caller gets its own instance and cannot corrupt the formatter's shared internal state.- Returns:
- A clone of the
DateFormatused for matching dates.
-
getField
Given a matcher that has matched the pattern specified bygetLogEntryPattern(), returns the field value from the match.- Parameters:
fieldName- The field name. Possible values are:"date" "class" "method" "logger" "level" "msg" "threadid" "exception" "traceId" "spanId"
m- The matcher. Must not benull .- Returns:
- The field value, or
null if the specified field does not exist.
-
getLogEntryPattern
Returns the regular expression pattern used for matching log entries.- Returns:
- The regular expression pattern used for matching log entries.
-