slf4j 占位符
slf4j format 占位符使用{}。
For example,
1 |
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,
1 |
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,
1 |
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
1 |
MessageFormatter.format("File name is C:\\\\{}.", "file.zip"); |
官方API https://www.slf4j.org/api/org/slf4j/helpers/MessageFormatter.html
发表评论