类 MessageFormatter
MessageFormatter
Formats messages according to very simple substitution rules. Substitutions
can be made 1, 2 or more arguments.
For example,
MessageFormatter.format("Hi {}.", "there")
will return the string "Hi there.".
The {} pair is called the formatting anchor. It serves to designate the location where arguments 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,
MessageFormatter.format("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 for whatever reason you need to place the string "{}" in the message without its formatting anchor meaning, then you need to escape the '{' character with '\', that is the backslash character. Only the '{' character should be escaped. There is no need to escape the '}' character. For example,
MessageFormatter.format("Set \\{} is not equal to {}.", "1,2");
will return the string "Set {} is not equal to 1,2.".
The escaping behavior just described can be overridden by escaping the escape character '\'. Calling
MessageFormatter.format("File name is C:\\\\{}.", "file.zip");
will return the string "File name is C:\file.zip".
The formatting conventions are different than those of MessageFormat
which ships with the Java platform. This is justified by the fact that
SLF4J's implementation is 10 times faster than that of MessageFormat.
This local performance difference is both measurable and significant in the
larger context of the complete logging processing chain.
See also format(String, Object) and
format(String, Object[]) methods for more details.
- 作者:
- Ceki Gülcü, Joern Huxhorn, TODAY
2019-11-11 21:40
-
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明private static voidbooleanArrayAppend(StringBuilder sbuf, boolean[] a) private static voidbyteArrayAppend(StringBuilder sbuf, byte[] a) private static voidcharArrayAppend(StringBuilder sbuf, char[] a) private static voiddeeplyAppendParameter(StringBuilder sbuf, Object o, Map<Object[], Object> seenMap) private static voiddoubleArrayAppend(StringBuilder sbuf, double[] a) private static voidfloatArrayAppend(StringBuilder sbuf, float[] a) static StringPerforms single argument substitution for the 'messagePattern' passed as parameter.static Stringprivate static voidintArrayAppend(StringBuilder sbuf, int[] a) (专用程序包) static booleanisDoubleEscaped(String messagePattern, int delimeterStartIndex) (专用程序包) static booleanisEscapedDelimeter(String messagePattern, int delimeterStartIndex) private static voidlongArrayAppend(StringBuilder sbuf, long[] a) private static voidobjectArrayAppend(StringBuilder sbuf, Object[] a, Map<Object[], Object> seenMap) private static voidsafeObjectAppend(StringBuilder sbuf, Object o) private static voidshortArrayAppend(StringBuilder sbuf, short[] a)
-
字段详细资料
-
构造器详细资料
-
MessageFormatter
public MessageFormatter()
-
-
方法详细资料
-
format
Performs single argument substitution for the 'messagePattern' passed as parameter.For example,
MessageFormatter.format("Hi {}.", "there");will return the string "Hi there.".- 参数:
messagePattern- The message pattern which will be parsed and formattedarg- The argument to be substituted in place of the formatting anchor- 返回:
- The formatted message
-
format
-
isEscapedDelimeter
-
isDoubleEscaped
-
deeplyAppendParameter
private static void deeplyAppendParameter(StringBuilder sbuf, Object o, Map<Object[], Object> seenMap) -
safeObjectAppend
-
objectArrayAppend
-
booleanArrayAppend
-
byteArrayAppend
-
charArrayAppend
-
shortArrayAppend
-
intArrayAppend
-
longArrayAppend
-
floatArrayAppend
-
doubleArrayAppend
-