英文:
How to solve this issue "Standard outputs should not be used directly to log anything "
问题
我需要一个打印语句。但是 Sonar 不允许这种类型。
String txt = "Something";
System.out.println("Print: " + txt);
预期输出:
Print: Something
我尝试了这种格式 logger.log()。但对于我们的要求不起作用。
英文:
I need a print statement. But sonar not allowed this type.
String txt="Something";
System.out.println("Print: "+txt);
Expected output:
Print: Something
I tried this format logger.log().its not working for our requirement.
答案1
得分: 0
如果记录器不符合您的要求,请通过配置使其符合要求。
有一些广泛使用的日志记录框架具有高度可配置性,我怀疑它们将无法执行您使用普通的 System.out.println
进行的任何操作。
例如,可以查看非常流行的 SLF4J
和作为日志提供程序的 Logback
。
英文:
If logger is not meeting your requirements, make it to do so by configuring it.
There are some widely used logging frameworks that are highly configurable and I doubt that they will not be able to do whatever you are doing with plain System.out.println
For example, check out very popular SLF4J
and Logback
as logging provider.
答案2
得分: 0
Sonarqube 不喜欢在日志函数的参数中使用 System.out
,也不喜欢如果你在传递给日志函数的参数中进行字符串连接或其他计算。在记录日志之前,请在单独的一行上构造完整的消息:
String txt = "Print: " + "Something";
String logMessage = "Print: " + txt;
logger.log(Level.INFO, logMessage);
英文:
Sonarqube does not like it if you use System.out
, or if you have string concatenation or other computation in the arguments you pass to the logging function. Construct the full message on a separate line before logging it:
String txt = "Print: " + "Something";
String logMessage = "Print: " + txt;
logger.log(Level.INFO, logMessage);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论