当运行java程序而不得到加强错误Poor Logging Practice: Use of a System Output Stream时,将日志输出打印到控制台的最简单方法是什么?
我想打印出几行,这样程序完成后它就会显示出来。System.out.println不被接受为最佳实践。我还可以使用什么其他方法?
public static void IBanUpdateTest(){
driver.get("http://10.10.10.10/demo-web-1.0-SNAPSHOT"); //define the url
String pageTitle = driver.getTitle(); //get the title of the webpage
System.out.println("The title of this page is ===> " +pageTitle);
Assert.assertEquals("IBan - Business ID code", pageTitle); //verify the title of the webpage
driver.findElement(By.id("0iban")).clear();//clear the input field before entering any value
driver.findElement(By.id("0iban")).sendKeys("5464564654");//enter the IBan Value
driver.findElement(By.id("0businessIdentifierCode")).clear();
driver.findElement(By.id("0businessIdentifierCode")).sendKeys("54645646548546465"); //enter the BIC value
driver.findElement(By.id("0updateRow")).click(); //click Update button
System.out.println("Successfully updated the row");
}发布于 2021-10-06 06:41:18
我相信这是最好的解决方案:
Logger logger = LoggerFactory.getLogger(YourClass.class);发布于 2021-10-06 01:46:12
登录System.out通常被认为是一种糟糕的做法,Fortify正确地标记了这一点。我不建议简单地忽略它/关闭警告。
正如其他人在评论中提到的那样,Spring Boot默认配置了Logback日志库。您可以在代码中配置记录器,但过一段时间后就会变得混乱,所以很多人发现添加Lombok库并使用它的@Log注解在编译时生成记录器是很方便的。然后你的代码就会变成如下所示:
@Log
public class MyClassThatLogs {
public void myMethod() {
log.info("myMethod was called");
}
}https://stackoverflow.com/questions/69458763
复制相似问题