如何解决这个问题"Standard outputs should not be used directly to log anything "

How to solve this issue "Standard outputs should not be used directly to log anything "

我需要打印语句。但是声纳不允许这种类型。

String txt="Something";
System.out.println("Print: "+txt);

预期输出:

Print: Something

我试过这种格式 logger.log()。它不符合我们的要求。

如果记录器不满足您的要求,请通过配置使其达到要求。

有一些广泛使用的高度可配置的日志记录框架,我怀疑它们无法完成您使用普通 System.out.println

所做的任何事情

例如,查看非常受欢迎的 SLF4JLogback 作为日志记录提供程序。

http://www.slf4j.org/

http://logback.qos.ch/

如果您使用 System.out,或者如果您在传递给日志函数的参数中有字符串连接或其他计算,Sonarqube 不喜欢它。在记录之前在单独的行中构造完整的消息:

String txt = "Print: " + "Something";

String logMessage = "Print: " + txt;
logger.log(Level.INFO, logMessage);