Class HpelFormatter
java.lang.Object
com.ibm.websphere.logging.hpel.reader.HpelFormatter
- Direct Known Subclasses:
HpelCBEFormatter
,HpelPlainFormatter
Abstract class for formatters used to convert HPEL log records into a formatted string output. This class
should be used for getting formatter instances.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Level
addCustomLevel
(String name, int intValue, String id, String resourceBundleName) Adds extra level recognizable by this formatter and Level.parse()static void
addCustomLevel
(Level level, String id) Adds level to be treated specially by this formatter.static Object[]
convertParameters
(Object[] parms) Returns an array of parameters that matches the input parms except: Parameters that are empty strings are converted to (2 double quotes)formatMessage
(RepositoryLogRecord record, Locale tmpLocale) Returns the formatted version of the record's message in a specified locale with any place holder parameters substituted with values.formatRecord
(RepositoryLogRecord record) Formats a RepositoryLogRecord using the formatter's localeabstract String
formatRecord
(RepositoryLogRecord record, Locale locale) Formats a RepositoryLogRecord using the locale specified.formatRecord
(LogRecord record) Formats a LogRecord using the formatter's localeabstract String
Gets the formatter's footer.static HpelFormatter
getFormatter
(String formatStyle) Returns the HpelFormatter subclass instance to be used for formatting a RepositoryLogRecord.abstract String[]
Gets the formatter's header.Returns the Properties that is used to populate the formatter's header.Returns the formatter's locale that will be used to localize the log record's date timestamp and message.Returns the ID of the time zone to be used in the formatted log record header timestampvoid
setCustomHeader
(String[] header) sets new customer header format specificationvoid
setDateFormat
(Locale locale, boolean isoDateFormat) Sets the formatter locale and the dateFormat that will be used to localize a log record being formatted.void
setHeaderProps
(Properties properties) Sets the Properties that is used to populate the formatter's header.void
setLineSeparator
(String lineSeparator) void
setStartDatetime
(long headerStartDatetime) void
setTimeZoneID
(String timeZoneId) Sets the ID of the time zone to be used in the formatted log record header timestampstatic String
translateMessage
(RepositoryLogRecord record, Locale tmpLocale)
-
Field Details
-
FORMAT_BASIC
Basic
type format used in legacy text log files- See Also:
-
FORMAT_ADVANCED
Advanced
type format used in legacy text log files- See Also:
-
FORMAT_CBE101
Common Base Event Format- See Also:
-
FORMAT_JSON
Json Format- See Also:
-
-
Constructor Details
-
HpelFormatter
public HpelFormatter()
-
-
Method Details
-
getFormatter
Returns the HpelFormatter subclass instance to be used for formatting a RepositoryLogRecord. The formatter returned is based on the formatStyle requested.- Parameters:
formatStyle
- the style of the HpelFormatter instance to be returned. Valid values must match (case-insensitive)FORMAT_BASIC
,FORMAT_ADVANCED
, orFORMAT_CBE101
- Returns:
- a HpelFormatter instance that matches the requested formatter style
- Throws:
IllegalArgumentException
- when the formatterName is invalid due to anull
value passed or a formatter name that is not recognized- See Also:
-
addCustomLevel
Adds extra level recognizable by this formatter and Level.parse()- Parameters:
name
- name of the levelintValue
- integer value of the levelid
- one character id to use for this level. If it'snull
first character of the level name will be usedresourceBundleName
- resource bundle to use for level name translation- Returns:
- newly generated level instance
-
addCustomLevel
Adds level to be treated specially by this formatter.- Parameters:
level
- level to be added to the special listid
- one character id to use for this level. If it'snull
first character of the level name will be used
-
setCustomHeader
sets new customer header format specification- Parameters:
header
- array of Strings containing optional parameters with name of the header value to use in them. For example:Java version: {java.version}
.
-
getTimeZoneID
Returns the ID of the time zone to be used in the formatted log record header timestamp- Returns:
- time zone ID
- See Also:
-
setTimeZoneID
Sets the ID of the time zone to be used in the formatted log record header timestamp- Parameters:
timeZoneId
- new timeZoneID attribute value.- Throws:
IllegalArgumentException
- when the time zone ID is not valid.
-
getLocale
Returns the formatter's locale that will be used to localize the log record's date timestamp and message.- Returns:
- the locale that will be used to localize the log record
-
setDateFormat
Sets the formatter locale and the dateFormat that will be used to localize a log record being formatted. The formatter locale will be used whenformatRecord(RepositoryLogRecord)
is invoked. It is possible to format a log record with a locale other than one set by this method usingformatRecord(RepositoryLogRecord, Locale)
. the formatter locale will be set to the system locale until this method gets invoked. The dateFormat can be either the default format or the ISO-8601 format.- Parameters:
locale
- the Locale to be used for localizing the log record,null
to disable message localization.flag
- to use ISO-8601 date format for output.
-
setHeaderProps
Sets the Properties that is used to populate the formatter's header. This Properties used in the parameter should be a Properties returned from invoking ServerInstanceLogRecordList.getHeader().- See Also:
-
getHeaderProps
Returns the Properties that is used to populate the formatter's header. -
formatMessage
Returns the formatted version of the record's message in a specified locale with any place holder parameters substituted with values.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()
- Parameters:
record
- log record to read the message from.tmpLocale
- locale to translate message into.- Returns:
- the fully localized and formatted message.
- See Also:
-
convertParameters
Returns an array of parameters that matches the input parms except: Parameters that are empty strings are converted to (2 double quotes)- Parameters:
parms
-- Returns:
- Object[]
-
translateMessage
- Parameters:
record
- log record to read the message from.tmpLocale
- locale to translate message into.- Returns:
- the fully localized message.
-
formatRecord
Formats a RepositoryLogRecord using the formatter's locale- Parameters:
record
- log record to be formatted- Returns:
- the resulting formatted string output.
-
formatRecord
Formats a RepositoryLogRecord using the locale specified.- Parameters:
record
- the RepositoryLogRecord to be formattedlocale
- the locale to use when formatting this record.- Returns:
- the formatted RepositoryLogRecord as string output.
-
formatRecord
Formats a LogRecord using the formatter's locale- Parameters:
record
- log record to be formatted- Returns:
- the resulting formatted string output.
-
getHeader
Gets the formatter's header. This method will return an empty array if the formatter does not have a header as part of the formatter's format style return the header as an array of strings -
getLineSeparator
-
setLineSeparator
-
setStartDatetime
public void setStartDatetime(long headerStartDatetime)
-