Tomcat 和 Eclipse 中的 System.out.println

发布于 2024-12-02 22:03:01 字数 143 浏览 0 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

败给现实 2024-12-09 22:03:01

我不会认为 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 making System.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.

梦巷 2024-12-09 22:03:01

除了很容易忘记并将其留在那里之外,我没有看到任何其他危害。因此最终会使日志文件变得不必要的冗长。至少,也许使用 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.

A君 2024-12-09 22:03:01

日志框架具有日志记录级别,可以将日志记录消息重定向到适当的日志簿、结构化日志记录,此外您还可以整齐地格式化日志等。使用 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.

掀纱窥君容 2024-12-09 22:03:01

不,你可以使用它。请注意,有时 Eclipse 浏览器与外部浏览器不同,并且 System.out.println 打印不同(主要是与路径有关)。
只是不使用 Eclispe 浏览器

No, you can use it. Note, that sometimes Eclipse browser differs from outside browsers and System.out.println prints different(mainly it concerns the paths).
Just not use Eclispe browser

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文