public abstract class HpelFormatter
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
protected class |
HpelFormatter.CustomHeaderLine
Helper class representing one line of the customary defined header.
|
Modifier and Type | Field and Description |
---|---|
protected HpelFormatter.CustomHeaderLine[] |
customHeader
Set of lines to use in the custom header.
|
protected static java.util.Map<java.util.logging.Level,java.lang.String> |
customLevels
Map between level and it's one character id.
|
protected java.text.DateFormat |
dateFormat |
static java.lang.String |
FORMAT_ADVANCED
"Advanced" type format used in legacy text log files
|
static java.lang.String |
FORMAT_BASIC
"Basic" type format used in legacy text log files
|
static java.lang.String |
FORMAT_CBE101
Common Base Event Format
|
static java.lang.String |
FORMAT_JSON
Json Format
|
protected java.util.Properties |
headerProps |
protected java.lang.String |
lineSeparator |
protected java.util.Locale |
locale
Locale this formatters uses for record messages and date formatting
|
protected static java.lang.String |
nullParamString |
protected java.util.TimeZone |
timeZone |
Constructor and Description |
---|
HpelFormatter() |
Modifier and Type | Method and Description |
---|---|
static void |
addCustomLevel(java.util.logging.Level level,
java.lang.String id)
Adds level to be treated specially by this formatter.
|
static java.util.logging.Level |
addCustomLevel(java.lang.String name,
int intValue,
java.lang.String id,
java.lang.String resourceBundleName)
Adds extra level recognizable by this formatter and Level.parse()
|
protected abstract java.lang.String |
appendUnusedParms(java.lang.String message,
java.lang.Object[] args)
Add parameters to the end of a message based on policy indicated by unusedParmHandling
parameter.
|
static java.lang.Object[] |
convertParameters(java.lang.Object[] parms)
Returns an array of parameters that matches the input parms except:
Parameters that are empty strings are converted to "" (2 double quotes)
|
java.lang.String |
formatMessage(RepositoryLogRecord record,
java.util.Locale tmpLocale)
Returns the formatted version of the record's message in a specified
locale with any place holder parameters substituted with values.
|
java.lang.String |
formatRecord(java.util.logging.LogRecord record)
Formats a LogRecord using the formatter's locale
|
java.lang.String |
formatRecord(RepositoryLogRecord record)
Formats a RepositoryLogRecord using the formatter's locale
|
abstract java.lang.String |
formatRecord(RepositoryLogRecord record,
java.util.Locale locale)
Formats a RepositoryLogRecord using the locale specified.
|
protected static void |
formatThreadID(RepositoryLogRecord r,
java.lang.StringBuilder buffer) |
protected java.lang.String |
formatUnlocalized(java.lang.String traceString,
java.lang.Object[] parms)
Used for WsLogRecords or CommonBaseEventLogRecords that specify REQUIRES_NO_LOCALIZATION,
tries to format, and if unsuccessful in using any parameters appends them per unusedParmHandling.
|
abstract java.lang.String |
getFooter()
Gets the formatter's footer.
|
static HpelFormatter |
getFormatter(java.lang.String formatStyle)
Returns the HpelFormatter subclass instance to be used for formatting a RepositoryLogRecord.
|
abstract java.lang.String[] |
getHeader()
Gets the formatter's header.
|
java.util.Properties |
getHeaderProps()
Returns the Properties that is used to populate the formatter's header.
|
java.lang.String |
getLineSeparator() |
java.util.Locale |
getLocale()
Returns the formatter's locale that will be used to localize the log record's date timestamp and message.
|
java.lang.String |
getTimeZoneID()
Returns the ID of the time zone to be used in the formatted log record header timestamp
|
void |
setCustomHeader(java.lang.String[] header)
sets new customer header format specification
|
void |
setHeaderProps(java.util.Properties properties)
Sets the Properties that is used to populate the formatter's header.
|
void |
setLineSeparator(java.lang.String lineSeparator) |
void |
setLocale(java.util.Locale locale)
Sets the formatter locale that will be used to localize a log record being formatted.
|
void |
setStartDatetime(long datetime) |
void |
setTimeZoneID(java.lang.String timeZoneId)
Sets the ID of the time zone to be used in the formatted log record header timestamp
|
static java.lang.String |
translateMessage(RepositoryLogRecord record,
java.util.Locale tmpLocale) |
protected static boolean |
verifyTimeZoneID(java.lang.String timeZoneID) |
public static final java.lang.String FORMAT_BASIC
public static final java.lang.String FORMAT_ADVANCED
public static final java.lang.String FORMAT_CBE101
public static final java.lang.String FORMAT_JSON
protected java.lang.String lineSeparator
protected java.util.Properties headerProps
protected java.util.Locale locale
protected java.util.TimeZone timeZone
protected java.text.DateFormat dateFormat
protected static final java.lang.String nullParamString
protected static final java.util.Map<java.util.logging.Level,java.lang.String> customLevels
protected HpelFormatter.CustomHeaderLine[] customHeader
public static HpelFormatter getFormatter(java.lang.String formatStyle)
formatStyle
- the style of the HpelFormatter instance to be returned. Valid values must match (case-insensitive)
FORMAT_BASIC
, FORMAT_ADVANCED
, or FORMAT_CBE101
java.lang.IllegalArgumentException
- when the formatterName is invalid due to a null
value passed or a formatter name
that is not recognizedTimeZone
public static java.util.logging.Level addCustomLevel(java.lang.String name, int intValue, java.lang.String id, java.lang.String resourceBundleName)
name
- name of the levelintValue
- integer value of the levelid
- one character id to use for this level. If it's null
first character of the level name will be usedresourceBundleName
- resource bundle to use for level name translationpublic static void addCustomLevel(java.util.logging.Level level, java.lang.String id)
level
- level to be added to the special listid
- one character id to use for this level. If it's null
first character of the level name will be usedpublic void setCustomHeader(java.lang.String[] header)
header
- array of Strings containing optional parameters with name of the header value to
use in them. For example: "Java version: {java.version}".public java.lang.String getTimeZoneID()
TimeZone
public void setTimeZoneID(java.lang.String timeZoneId)
timeZoneId
- new timeZoneID attribute value.java.lang.IllegalArgumentException
- when the time zone ID is not valid.public java.util.Locale getLocale()
public void setLocale(java.util.Locale locale)
formatRecord(RepositoryLogRecord)
is invoked. It is possible to format a log record with a locale other than
one set by this method using formatRecord(RepositoryLogRecord, Locale)
. the formatter locale will be set to the system
locale until this method gets invoked.locale
- the Locale to be used for localizing the log record, null
to disable message localization.public void setHeaderProps(java.util.Properties properties)
ServerInstanceLogRecordList
public java.util.Properties getHeaderProps()
public java.lang.String formatMessage(RepositoryLogRecord record, java.util.Locale tmpLocale)
In cases where localization is successful, the formatted message is the localized message with any place holder values filled in with corresponding parameter values.
In cases where the localized message is null
, the formatted message
is the raw message with any place holder values filled in with
corresponding parameter values.
This is the same behavior as found in
LogRecord.getMessage()
record
- log record to read the message from.tmpLocale
- locale to translate message into.LogRecord.getMessage()
public static java.lang.Object[] convertParameters(java.lang.Object[] parms)
parms
- protected java.lang.String formatUnlocalized(java.lang.String traceString, java.lang.Object[] parms)
protected abstract java.lang.String appendUnusedParms(java.lang.String message, java.lang.Object[] args)
message
- Message to append arguments ontoargs
- Arguments to append to messagepublic static java.lang.String translateMessage(RepositoryLogRecord record, java.util.Locale tmpLocale)
record
- log record to read the message from.tmpLocale
- locale to translate message into.public java.lang.String formatRecord(RepositoryLogRecord record)
record
- log record to be formattedpublic abstract java.lang.String formatRecord(RepositoryLogRecord record, java.util.Locale locale)
record
- the RepositoryLogRecord to be formattedlocale
- the locale to use when formatting this record.public java.lang.String formatRecord(java.util.logging.LogRecord record)
record
- log record to be formattedpublic abstract java.lang.String[] getHeader()
public abstract java.lang.String getFooter()
protected static boolean verifyTimeZoneID(java.lang.String timeZoneID)
protected static void formatThreadID(RepositoryLogRecord r, java.lang.StringBuilder buffer)
public java.lang.String getLineSeparator()
public void setLineSeparator(java.lang.String lineSeparator)
public void setStartDatetime(long datetime)