我正在重构一些当前使用System.out.println
和MessageFormat
的代码,以便将来使用SLF4j进行记录。
手头的代码通常经常按索引引用参数,例如:
System.out.println(MessageFormat.format("WARN: Found coordinates [{0}] are too close to the target vertex [{1}], but are not well connected, path length [{2}]. Vertex coordinate [{3}]. Distance from vertex coordinate: distance [{4,number,#.######}]. Distance from found coordinate: [{5,number,#.######}].",
foundCoordinate, fc1, pathLength, vertexCoordinate, dvfc1, dfc1));
日志消息中的参数顺序并不总是与format
方法中的参数顺序匹配。
我知道我可以在SLF4J日志方法中使用{}
als占位符作为参数。但是,当日志消息中的参数顺序与方法参数不匹配时,我将不得不对方法中的参数进行重新排序,这将使重构更加耗时。
在SLF4J日志方法({someindex}
的{{1}}的模拟中)是否可以通过索引引用自变量?这样做的具体语法是什么? / p>
为澄清起见,我希望能够执行以下操作:
MessageFormat
仅仅不能用LOGGER.warn("WARN: Found coordinates [{0}] are too close to the target vertex [{1}], but are not well connected, path length [{2}]. Vertex coordinate [{3}]. Distance from vertex coordinate: distance [{4,number,#.######}]. Distance from found coordinate: [{5,number,#.######}].",
foundCoordinate, fc1, pathLength, vertexCoordinate, dvfc1, dfc1);
的SLF4j语法来引用第三个日志消息参数。