Tomcat 和 Eclipse 中的 System.out.println
我在 Eclipse 中运行 Tomcat。仅在开发过程中使用 System.out.println 在 Eclipse 控制台上查看一些输出进行测试有什么坏处吗?我知道我听说这是不好的做法,但我不记得为什么。对于这个应用程序,我不需要任何像 log4j 这样的奇特东西。
I am running Tomcat inside Eclipse. Is there any harm in using System.out.println only during development to see some output on the Eclipse console for testing? I know I have heard that this is bad practice, but I can't remember why. I don't need anything fancy like log4j for this app.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不会认为 log4j 特别复杂。特别是,有很多关于在 Tomcat 中使用它的信息,并且能够在开发期间以及稍后实际部署代码时使用相同的日志记录基础设施非常有用。
就使用 System.out.println 而言 - 我怀疑它会造成任何真正重大的伤害,但我不希望在制作 System.out 上投入那么多精力 Tomcat 中的输出效率与 log4j 中的日志记录相同。它的灵活性也较差 - 您最终更有可能在代码中添加和删除日志记录,因为您无法通过配置轻松完成此操作。
换句话说:虽然使用 System.out.println 可能还不错,但我认为值得投入相对较少的时间来使用更灵活的日志记录解决方案(无论是 log4j或其他东西)。这是一次性的成功,但具有持续的好处。
I wouldn't call log4j particularly complex. In particular, there's a lot of information out there about using it in Tomcat, and it's useful to be able to use the same logging infrastructure during development and later when you actually deploy your code.
In terms of using
System.out.println
- I doubt that it'll do any really significant harm, but I wouldn't expect as much effort to have been put into makingSystem.out
output efficient in Tomcat as logging in log4j. It's also a lot less flexible - you're more likely to end up adding and removing logging in your code because you can't easily do it via configuration.In other words: while it's probably not too bad to use
System.out.println
, I think it would be worth investing the relatively small amount of time required to use a more flexible logging solution (whether that's log4j or something else). It's a one-off hit with an ongoing benefit.除了很容易忘记并将其留在那里之外,我没有看到任何其他危害。因此最终会使日志文件变得不必要的冗长。至少,也许使用 System.err 而不是 out,这样您就可以保持正常输出干净。
I don't see any harm other than the very simple probability of forgetting and leaving it there. Thus eventually leaving logs files unnecessarily verbose. At the very least, perhaps use System.err instead of out so you can keep normal output clean.
日志框架具有日志记录级别,可以将日志记录消息重定向到适当的日志簿、结构化日志记录,此外您还可以整齐地格式化日志等。使用 System.out.println 可以简单地将其转储到控制台上,因此如果您的应用程序记录跟踪消息和错误在开发过程中,您的整个控制台将被填满,实际上使其无法追踪。
如果您正在进行认真的应用程序开发,则应该在开发过程中使用日志记录框架。如果您不相信我的想法,但是 GIYF。
Logging frameworks have logging levels, can redirect logging messages to appropriate log books, structured logging, plus you could neatly format the logs etc. Using System.out.println simple dumps it on the console, so if your application logs trace messages along with errors while development, you would have your entire console filled up, literally making it untraceble.
If you are doing serious application development you should use a logging framework during development. And incase you werent convinced by my thoughts, yet GIYF.
不,你可以使用它。请注意,有时 Eclipse 浏览器与外部浏览器不同,并且 System.out.println 打印不同(主要是与路径有关)。
只是不使用
Eclispe
浏览器No, you can use it. Note, that sometimes
Eclipse
browser differs from outside browsers andSystem.out.println
prints different(mainly it concerns the paths).Just not use
Eclispe
browser