Tomcat 使用 log4j 进行日志记录?

发布于 2024-10-02 08:35:49 字数 241 浏览 1 评论 0原文

我已将 Apache tomcat 5.5 作为服务安装在我的系统中。我还使用 log4j 为 Web 应用程序添加了一个自定义日志文件。每当我在 JSP 页面中使用 system.out.println("some text") 语句时,默认情况下它都会转到 tomcat.i 的日志目录中的 stdout.log 文件。我想要 system.out.println("some text" ) 语句的输出可以写入自定义日志文件而不是 stdout.log 文件中。

I have installed Apache tomcat 5.5 as a service in my system. Also i added a custom logging file using log4j for a web application. whenever i used system.out.println("some text") statement in my JSP page by default it goes to the stdout.log file which is in the logs directory of tomcat.i want system.out.println("some text") statement's output to be written in a custom log file rather than the stdout.log file is it possible.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

漫雪独思 2024-10-09 08:35:49

作为服务启动时,您可以从服务管理器配置 stdout 和 stderr 消息的文件位置。

尽管我同意@Brabster,但当您想要进入生产环境时,您应该使用 log4j 日志记录而不是 System.out。

此链接有屏幕截图< /a> 和参考。请参阅“测试#2”部分

When started as a service, you can configure the file locations for the stdout and stderr messages from the Service Manager.

Though I agree with @Brabster, you should be using log4j logging instead of System.out when you want to move into production.

This link has a screenshot and reference. See section "Testing #2"

但可醉心 2024-10-09 08:35:49

不确定是否可以重定向 System.out 即使你可以,它也会非常令人困惑,但是如果你已经设置了 log4j 设施,为什么不使用它们呢?

log.info("我的消息"); 而不是 System.out.println("我的消息");

如果您确定如何在 Tomcat 中使用 log4j,这里有一个教程这应该可以帮助你开始。

Not sure if you can redirect System.out and even if you could it'd be mighty confusing, but why aren't you using the log4j facilities if you've set them up?

i.e. log.info("my message"); instead of System.out.println("my message");?

If you're note sure how to use log4j with Tomcat, there's a tutorial here that should help you get going.

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