如何在运行时调整 log4j 级别?

发布于 2024-07-29 00:31:36 字数 170 浏览 1 评论 0原文

我有一个在 Tomcat 5.5 上运行的简单 Web 应用程序,使用 log4j 进行日志记录。 有时我需要将日志记录推送到“DEBUG”(调试),但大多数时候我对“INFO”(信息)感到满意。

我可以更改我的配置 xml 并重新启动应用程序,但我更喜欢动态切换日志级别。 有这方面的标准技术吗?

I have a simple web app running on Tomcat 5.5 with log4j for logging. Occasionally I need to push the logging down to DEBUG but most of the time I'm happy with INFO.

I can change my config xml and restart the app but I would prefer to switch the log levels on the fly. Is there a standard technique for this?

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

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

发布评论

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

评论(2

魄砕の薆 2024-08-05 00:31:36

只需使用编程 API

logger.setLevel(Level.DEBUG)

在您的程序中,当您需要更详细的日志输出时,并

logger.setLevel(Level.INFO)

使其再次变得不那么详细。

Just use the programmatic API:

logger.setLevel(Level.DEBUG)

in your program when you need more verbose logging output, and

logger.setLevel(Level.INFO)

to make it less verbose again.

罪歌 2024-08-05 00:31:36

我创建了一个新的 java 应用程序模块(jar)来在运行时在 Web 界面中执行此操作,并且还有一个用于查看日志结果的页面。
配置jar很简单:必须放在/WEB-INF/lib文件夹中,并在/WEB-INF/web.xml中添加到servlet的映射> 文件。

项目站点:http://www.log4jwebtracker.com

I created a new java application module (jar) to do this in a web interface at runtime, and also have a page to view the log result.
Configure the jar is very simple: must be placed in the /WEB-INF/lib folder, and add a mapping to the servlet in the /WEB-INF/web.xml file.

Project site: http://www.log4jwebtracker.com

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