public class ParameterizedMessage extends Object implements Message, StringBuilderFormattable
This class was originally written for Lilith by Joern Huxhorn where it is licensed under the LGPL. It has been relicensed here with his permission providing that this attribution remain.
Modifier and Type | Field and Description |
---|---|
static String |
ERROR_MSG_SEPARATOR
Separator for error messages.
|
static String |
ERROR_PREFIX
Prefix for errors.
|
static String |
ERROR_SEPARATOR
Separator for errors.
|
static String |
ERROR_SUFFIX
Suffix for errors.
|
static String |
RECURSION_PREFIX
Prefix for recursion.
|
static String |
RECURSION_SUFFIX
Suffix for recursion.
|
Constructor and Description |
---|
ParameterizedMessage(String messagePattern,
Object... arguments)
Constructs a ParameterizedMessage which contains the arguments converted to String as well as an optional
Throwable.
|
ParameterizedMessage(String messagePattern,
Object arg)
Constructor with a pattern and a single parameter.
|
ParameterizedMessage(String messagePattern,
Object[] arguments,
Throwable throwable)
Creates a parameterized message.
|
ParameterizedMessage(String messagePattern,
Object arg0,
Object arg1)
Constructor with a pattern and two parameters.
|
ParameterizedMessage(String messagePattern,
String[] arguments,
Throwable throwable)
Deprecated.
Use constructor ParameterizedMessage(String, Object[], Throwable) instead
|
Modifier and Type | Method and Description |
---|---|
static int |
countArgumentPlaceholders(String messagePattern)
Counts the number of unescaped placeholders in the given messagePattern.
|
static String |
deepToString(Object o)
This method performs a deep toString of the given Object.
|
boolean |
equals(Object o) |
static String |
format(String messagePattern,
Object[] arguments)
Replace placeholders in the given messagePattern with arguments.
|
void |
formatTo(StringBuilder buffer)
Writes a text representation of this object into the specified
StringBuilder , ideally without allocating
temporary objects. |
String |
getFormat()
Returns the message pattern.
|
String |
getFormattedMessage()
Returns the formatted message.
|
Object[] |
getParameters()
Returns the message parameters.
|
Throwable |
getThrowable()
Returns the Throwable that was given as the last argument, if any.
|
int |
hashCode() |
static String |
identityToString(Object obj)
This method returns the same as if Object.toString() would not have been
overridden in obj.
|
String |
toString() |
public static final String RECURSION_PREFIX
public static final String RECURSION_SUFFIX
public static final String ERROR_PREFIX
public static final String ERROR_SEPARATOR
public static final String ERROR_MSG_SEPARATOR
public static final String ERROR_SUFFIX
@Deprecated public ParameterizedMessage(String messagePattern, String[] arguments, Throwable throwable)
messagePattern
- The message "format" string. This will be a String containing "{}" placeholders
where parameters should be substituted.arguments
- The arguments for substitution.throwable
- A Throwable.public ParameterizedMessage(String messagePattern, Object[] arguments, Throwable throwable)
messagePattern
- The message "format" string. This will be a String containing "{}" placeholders
where parameters should be substituted.arguments
- The arguments for substitution.throwable
- A Throwable.public ParameterizedMessage(String messagePattern, Object... arguments)
If the last argument is a Throwable and is NOT used up by a placeholder in the message pattern it is returned
in 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.public ParameterizedMessage(String messagePattern, Object arg)
messagePattern
- The message pattern.arg
- The parameter.public ParameterizedMessage(String messagePattern, Object arg0, Object arg1)
messagePattern
- The message pattern.arg0
- The first parameter.arg1
- The second parameter.public Object[] getParameters()
getParameters
in interface Message
public Throwable getThrowable()
getThrowable
in interface Message
public String getFormattedMessage()
getFormattedMessage
in interface Message
public void formatTo(StringBuilder buffer)
StringBuilderFormattable
StringBuilder
, ideally without allocating
temporary objects.formatTo
in interface StringBuilderFormattable
buffer
- the StringBuilder to write intopublic static String format(String messagePattern, Object[] arguments)
messagePattern
- the message pattern containing placeholders.arguments
- the arguments to be used to replace placeholders.public static int countArgumentPlaceholders(String messagePattern)
messagePattern
- the message pattern to be analyzed.public static String deepToString(Object o)
It should be noted that neither AbstractMap.toString() nor AbstractCollection.toString() implement such a behavior. They only check if the container is directly contained in itself, but not if a contained container contains the original one. Because of that, Arrays.toString(Object[]) isn't safe either. Confusing? Just read the last paragraph again and check the respective toString() implementation.
This means, in effect, that logging would produce a usable output even if an ordinary System.out.println(o) would produce a relatively hard-to-debug StackOverflowError.
o
- The object.public static String identityToString(Object obj)
Note that this isn't 100% secure as collisions can always happen with hash codes.
Copied from Object.hashCode():
As much as is reasonably practical, the hashCode method defined by
class Object
does return distinct integers for distinct
objects. (This is typically implemented by converting the internal
address of the object into an integer, but this implementation
technique is not required by the Java™ programming language.)
obj
- the Object that is to be converted into an identity string.Copyright © 1999-1969 The Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.