public final class MessageFormatter
extends java.lang.Object
Replacement for org.slf4j.helpers.MessageFormatter.
In contrast to the mentioned class, the formatting of message pattern and arguments into the actual message is split into three parts:
That way only the first two steps have to be done during event creation while the most expensive part, i.e. the actual construction of the message, is only done on demand.
Modifier and Type | Class and Description |
---|---|
static class |
MessageFormatter.ArgumentResult
This is just a simple class containing the result of an evaluateArgument call.
|
Modifier and Type | Method and Description |
---|---|
static int |
countArgumentPlaceholders(java.lang.String messagePattern)
Counts the number of unescaped placeholders in the given messagePattern.
|
static MessageFormatter.ArgumentResult |
evaluateArguments(java.lang.String messagePattern,
java.lang.Object[] arguments)
This method returns a MessageFormatter.ArgumentResult which contains the arguments converted to String
as well as an optional Throwable.
|
static java.lang.String |
format(java.lang.String messagePattern,
java.lang.String[] arguments)
Replace placeholders in the given messagePattern with arguments.
|
public static java.lang.String format(java.lang.String messagePattern, java.lang.String[] arguments)
messagePattern
- the message pattern containing placeholders.arguments
- the arguments to be used to replace placeholders.public static int countArgumentPlaceholders(java.lang.String messagePattern)
messagePattern
- the message pattern to be analyzed.public static MessageFormatter.ArgumentResult evaluateArguments(java.lang.String messagePattern, java.lang.Object[] arguments)
This method returns a MessageFormatter.ArgumentResult which contains the arguments converted to String as well as an optional Throwable.
If the last argument is a Throwable and is NOT used up by a placeholder in the message pattern it is returned in MessageFormatter.ArgumentResult.getThrowable() and won't be contained in the created String[].
If it is used up getThrowable will return null even if the last argument was a Throwable!
messagePattern
- the message pattern that to be checked for placeholders.arguments
- the argument array to be converted.