如何使用 JDK8 和 JDK11 拥有相同的 slf4j 日志?
我的 java Slf4j 记录器:
log.info("---> {} {}", "When", String.format(matcher.group(1).replaceAll("\\{\\S+\\}", "{%s}").replace("(\\?)", ""), invocation.getArguments()));
JDK8 在 java 8 中的跟踪:
---> When I update text {bakery.DemoPage-input_text_field} with {Jenkins T5}
JDK11 在 java 8 中的跟踪:
---> When "I update text {bakery.DemoPage-input_text_field} with {Jenkins T5}"
编辑:
我尝试了这个但结果相同:
String message = MessageFormat.format("---> {0} {1}",
stepAnnotation.annotationType().getSimpleName(),
String.format(matcher.group(1).replaceAll("\\{\\S+\\}", "{%s}").replace("(\\?)", ""), invocation.getArguments())
);
log.info(message);
编辑(如果你想要一个更简单的案例):
log.info("---> {} {}", "When", String.format("I update text {%s} with {%s}", "bakery.DemoPage-input_text_field", "Jenkins T5"));
用@M编辑。Deinum 提案但不工作
log.info("---> {} " + matcher.group(1).replaceAll("\\{\\S+\\}", "{}").replace("(\\?)", ""), stepAnnotation.annotationType().getSimpleName(), invocation.getArguments());
---> When "I update text [bakery.DemoPage-input_text_field, Jenkins T5, []] with {}"
编辑:我尝试使用外部替换的其他建议:
String mes = String.format(matcher.group(1).replaceAll("\\{\\S+\\}", "{%s}").replace("(\\?)", ""), invocation.getArguments());
log.info("---> {} {}", stepAnnotation.annotationType().getSimpleName(), mes);
---> When "I update text {bakery.DemoPage-input_text_field} with {Jenkins T5}"