1. Logger 日志输出请使用占位符 {}
格式: logger.error("错误信息,占位符1{},占位符2{}", 参数1, 参数2);
private static final Logger LOG = LoggerFactory.getLogger(Wombat.class);
LOG.debug("There are now " + count + " user accounts: " + userAccountList); // slow
LOG.debug("There are now {} user accounts: {}", count, userAccountList); // faster
2. 控制台输出 使用占位符
//1. String.format
String stringFormat = "lexical error at position %s, encountered %s, expected %s ";
System.out.println(String.format(stringFormat, 123, 100, 456));
//2.MessageFormat.format
String messageFormat ="lexical error at position {0}, encountered {1}, expected {2}";
System.out.println(MessageFormat.format(messageFormat, new Date(), 100, 456));
关于:String.format :
%后面可以是d、f、s等中间也可以加其他参数。只能用于String类对象中,不能用于MessageFormat类对象。