public class PatternParser extends Object
This class is not guaranteed to be threadsafe.
| Constructor and Description |
|---|
PatternParser()
Creates and initializes a PatternParser instance.
|
| Modifier and Type | Method and Description |
|---|---|
String |
expand(LogEntry logEntry)
Creates a text representation of a LogEntry by applying a
user-specified Pattern string.
|
boolean |
getIndent()
Returns if the expand method automatically intends log packets like in the Views of the SmartInspect Console.
|
String |
getPattern()
Returns the pattern string for this PatternParser object.
|
void |
setIndent(boolean indent)
Sets if the expand method automatically indents log packets like
in the Views of the SmartInspect Console.
|
void |
setPattern(String pattern)
Sets the pattern string for this PatternParser object.
|
public PatternParser()
public String expand(LogEntry logEntry)
logEntry - The LogEntry whose text representation should be computed by
applying the current pattern string. All
recognized variables in the pattern string are replaced with
the actual values of this LogEntrypublic String getPattern()
The pattern string influences the way a text representation of a LogEntry object is created. A pattern string consists of a list of so called variable and literal tokens. When a string representation of a LogEntry object is created, the variables are replaced with the actual values of the LogEntry object. For a list of valid tokens, please refer to the documentation of the setPattern method.
public void setPattern(String pattern)
The pattern string influences the way a text representation of a LogEntry object is created. A pattern string consists of a list of so called variable and literal tokens. When a string representation of a LogEntry object is created, the variables are replaced with the actual values of the LogEntry object.
Variables have a unique name, are surrounded with '%' characters and can have an optional options string enclosed in curly braces like this: %name{options}%.
You can also specify the minimum width of a value like this: %name,width%. Width must be a valid positive or negative integer. If the width is greater than 0, formatted values will be right-aligned. If the width is less than 0, they will be left-aligned.
The following table lists the available variables together with the corresponding LogEntry method/property.
| Variable | Corresponding Method |
|---|---|
| %appname% | LogEntry.getAppName |
| %color% | LogEntry.getColor |
| %hostname% | LogEntry.getHostName |
| %level% | LogEntry.getLevel |
| %logentrytype% | LogEntry.getLogEntryType |
| %process% | LogEntry.getProcessId |
| %session% | LogEntry.getSessionName |
| %thread% | LogEntry.getThreadId |
| %timestamp% | LogEntry.getTimestamp |
| %title% | LogEntry.getTitle |
| %viewerid% | LogEntry.getViewerId |
For the timestamp token, you can use the options string to pass a custom date/time format string. This can look as follows: %timestamp{HH:mm:ss.SSS}%.
The format string must be a valid Java DateFormat format string. The default format string used by the timestamp token is "yyyy-MM-dd HH:mm:ss.SSS".
Literals are preserved as specified in the pattern string. When a specified variable is unknown, it is handled as literal.
Example:
[%timestamp%] %level,8%: %title% [%timestamp%] %session%: %title% (Level: %level%)
pattern - The new pattern stringpublic boolean getIndent()
public void setIndent(boolean indent)
Log Entry packets of type EnterMethod increase the indentation and packets of type LeaveMethod decrease it.
indent - Should be true if the expand method should automatically indent
log packets and false otherwiseCopyright © 2023. All rights reserved.