public abstract class Token extends Object
This is the abstract base class for all available tokens. Derived classes are not documented for clarity reasons. To create a suitable token object for a given token string, you can use the TokenFactory class.
Note: This class is not guaranteed to be threadsafe.
| Constructor and Description |
|---|
Token() |
| Modifier and Type | Method and Description |
|---|---|
abstract String |
expand(LogEntry logEntry)
Creates a string representation of a variable or literal token.
|
boolean |
getIndent()
Indicates if this token supports indenting.
|
String |
getOptions()
Returns the optional options string for this token.
|
String |
getValue()
Returns the raw string value of the parsed pattern string for
this token.
|
int |
getWidth()
Returns the minimum width of this token.
|
void |
setOptions(String options)
Sets the optional options string for this token.
|
void |
setValue(String value)
Sets the raw string value of the parsed pattern string for this token.
|
void |
setWidth(int width)
Sets the minimum width of this token.
|
public abstract String expand(LogEntry logEntry)
For a literal token, the supplied LogEntry argument is ignored and the value property is returned.
logEntry - The LogEntry to use to create the string representationpublic String getValue()
This method returns the raw string of this token as found in the parsed pattern string. For a variable, this property is set to the variable name surrounded with '%' characters and an optional options string like this: %name{options}%. For a literal, this property can have any value.
public void setValue(String value)
This method sets the raw string of this token as found in the parsed pattern string. For a variable, this property is set to the variable name surrounded with '%' characters and an optional options string like this: %name{options}%. For a literal, this property can have any value.
value - The new value of this tokenpublic String getOptions()
A variable token can have an optional options string. In the raw string representation of a token, an options string can be specified in curly brackets after the variable name like this: %name{options}%. For a literal, this property is always set to an empty string.
public void setOptions(String options)
A variable token can have an optional options string. In the raw string representation of a token, an options string can be specified in curly braces after the variable name like this: %name{options}%. For a literal, this property is always set to an empty string.
options - The new options for this tokenpublic boolean getIndent()
This method always returns false unless this token represents the title token of a pattern string. This method is used in the PatternParser.expand() method to determine if a token allows indenting.
public void setWidth(int width)
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.
For a literal, this property is always set to 0.
width - The new minimum width of this tokenpublic int getWidth()
A variable token can have an optional width modifier. In the raw string representation of a token, a width modifier can be specified after the variable name 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.
For a literal, this property is always set to 0.
Copyright © 2023. All rights reserved.