Log4J Swing Appender

发布于 2024-08-03 09:18:58 字数 67 浏览 1 评论 0原文

我需要将 log4j 内容附加到 Swing 组件(JTextArea 或类似组件)。有一个通用的方法可以做到这一点吗?

I need to append log4j content to a Swing component (JTextArea or similar). Is there a common way to do this?

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

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

发布评论

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

评论(3

感情洁癖 2024-08-10 09:18:58

我最终没有引入外部库,而是编辑了 log4j.properties 文件以包含以下内容:

log4j.rootCategory=DEBUG, app
log4j.appender.app=path.to.class.extending.WriterAppender

然后,我采用观察者模式将数据发布到 GUI 的 JTextArea 中。

Instead of introducing an external library, I ended up editing the log4j.properties file to include the following:

log4j.rootCategory=DEBUG, app
log4j.appender.app=path.to.class.extending.WriterAppender

Then I employed an observer pattern to post the data into my GUI's JTextArea.

二货你真萌 2024-08-10 09:18:58

感谢 Google,我显然发现了 Log4j-Swing-Appender

Thanks to Google, I've obviously discovered the Log4j-Swing-Appender.

∞梦里开花 2024-08-10 09:18:58

要使包装目标组件(例如 JTextArea)的 JScrollPane 自动向下滚动以显示最新的日志条目,请考虑调用:

  org.apache.log4j.lf5.viewer.LF5SwingUtils.makeVerticalScrollBarTrack(scrollPane); 

to make the JScrollPane wrapping the target component (e.g. JTextArea) automatically scroll down to show the latest log entries, consider calling:

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