@FunctionalInterface
public interface LogMessage
Modifier and Type | Method and Description |
---|---|
void |
appendTo(java.util.Locale locale,
java.lang.Appendable appendable)
Append the log message to the given
Appendable . |
static LogMessage |
messageFormat(java.lang.String pattern,
java.lang.Object... args)
Construct a
LogMessage using a MessageFormat . |
static LogMessage |
patternFormat(java.lang.String pattern,
java.lang.Object... args)
Construct a
LogMessage using a pattern format. |
static LogMessage |
stringFormat(java.lang.String format,
java.lang.Object... args)
Construct a
LogMessage for a formatted String . |
static LogMessage stringFormat(java.lang.String format, java.lang.Object... args)
LogMessage
for a formatted String
.
The formatting of the message will be deferred until the message is appended to a log, so all arguments should remain constant while the log is being written.
format
- A format string, as per String.format(String, Object...)
.args
- The arguments for the format.LogMessage
instance.static LogMessage messageFormat(java.lang.String pattern, java.lang.Object... args)
LogMessage
using a MessageFormat
.
The formatting of the message will be deferred until the message is appended to a log, so all arguments should remain constant while the log is being written.
pattern
- A pattern string, as per MessageFormat.format(String, Object...)
.args
- The arguments for the pattern.LogMessage
instance.static LogMessage patternFormat(java.lang.String pattern, java.lang.Object... args)
LogMessage
using a pattern format.
The formatting of the message will be deferred until the message is appended to a log, so all arguments should remain constant while the log is being written.
Formats messages according to very simple substitution rules, and is typically much faster than the other formatting methods. For example,
LogMessage.patternFormat("Hi {}.", "there")will log the string "Hi there.".
The {} pair is serves to designate the location where an argument need to be substituted within the message pattern.
In case your message contains the '{' or the '}' character, you do not have to do anything special unless the '}' character immediately follows '{'. For example,
LogMessage.patternFormat("Set {1,2,3} is not equal to {}.", "1,2");will return the string "Set {1,2,3} is not equal to 1,2.".
If you need to place a literal "{}" in the message, then you need to escape the '{' character with a backslash character, '\'. Only the '{' character should be escaped. There is no need to escape the '}' character. For example,
LogMessage.patternFormat("Set \\{} is not equal to {}.", "1,2");will return the string "Set {} is not equal to 1,2.".
The escape character can itself be escaped. For example,
LogMessage.patternFormat("File name is C:\\\\{}.", "file.zip");will return the string "File name is C:\file.zip".
pattern
- A pattern string.args
- The arguments for the pattern.LogMessage
instance.void appendTo(java.util.Locale locale, java.lang.Appendable appendable) throws java.io.IOException
Appendable
.locale
- The Locale
that should be used if the message requires localization.appendable
- The Appendable
the message should be appended to.java.io.IOException
- If any of the appendable methods throw an IOException
then it will be propagated.