Logger vs. System.out.println [英] Logger vs. System.out.println
问题描述
我正在使用PMD插件进行eclipse,并且在使用 System.out.println()
时给出了一个错误,解释如下:
I'm using the PMD plugin for eclipse and it gives me an error when using System.out.println()
with the explanation:
系统(out | err).print被用于考虑使用记录器。
System.(out|err).print is used, consider using a logger.
我的问题是 - 什么是记录器?怎么用来打印到屏幕上?为什么会更好?
My question is - What is a Logger? How is it used to print to the screen? Why is it better?
推荐答案
请参阅 log4j的简短介绍。
问题是使用 System.out
打印调试或诊断信息。这是一个不好的做法,因为您不能轻易地更改日志级别,关闭它,自定义等。
The issue is in using System.out
to print debugging or diagnostic information. It is a bad practice because you cannot easily change log levels, turn it off, customize it, etc.
但是,如果您合法使用系统.out
以向用户打印信息,则可以忽略此警告。
However if you are legitimately using System.out
to print information to the user, then you can ignore this warning.
这篇关于Logger vs. System.out.println的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!