System.out.print 为什么是一种不好的实践?

J2EE 码拜 8年前 (2016-01-29) 1449次浏览
System.out.print 用在项目里,为什么是一种不好的实践?
解决方案:5分
System.out.print
在编写的时候 随便写
项目一旦上线
就肯定不用System.out.print了
解决方案:5分
原因是system这种语句是硬编码,不能控制输出,像log4j的日志框架可以控制需要的输出的日志等级。
解决方案:5分
能不用尽量不用,偶尔用来调试调试也无妨
解决方案:5分
学习的时候可以用,但是开发的时候还是用日志,最简单的一条,System.out.println输出的内容不能保存到文件,光这一点就足以不推荐使用。
解决方案:5分
原因是System.out.println 只打印在控制台,打印完就过去了。也就是说除非你一直盯着程序跑,你才能看到System.out.println出的内容。而Logger可以将内容写入日志方便程序运行一段时候后排查问题。
假如是测试阶段用System.out.println 问题也不大。而假如以及是在正式运行的程序System.out.println显然没办法帮你查错。
解决方案:10分
System.out.println没关系,,放心大胆的用就是了。“只用System.out.println”     才是不好的实践。
99%的System.out.println 不会影响性能的。
原因是每个方法都有缺点。log4j也是,没法很好的查询。所以我们也常常把日志扔到数据库里面使用sql方便查询。但是不能说log4j是个不好的实践。
我们项目常用的方法是日志数据库放一份,Log4g放一份。各个功能点使用file Api放一份,System.out.println也根据必要尽管的用。
一般性能占用都不超过10% ..对于一个重要系统来说,日志就是全面的全程的测试覆盖,性能占用50%都不为过。
解决方案:5分
print streams ignore many issues involved in internationalization and error checking. This makes System.out easy to use in quick and dirty hacks and simple examples, while simultaneously making it unsuitable for production code, which should use
the java.io.PrintWriter class  instead。

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明System.out.print 为什么是一种不好的实践?
喜欢 (0)
[1034331897@qq.com]
分享 (0)