Log4J Swing Appender
我需要将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我最终没有引入外部库,而是编辑了 log4j.properties 文件以包含以下内容:
然后,我采用观察者模式将数据发布到 GUI 的 JTextArea 中。
Instead of introducing an external library, I ended up editing the log4j.properties file to include the following:
Then I employed an observer pattern to post the data into my GUI's JTextArea.
感谢 Google,我显然发现了 Log4j-Swing-Appender。
Thanks to Google, I've obviously discovered the Log4j-Swing-Appender.
要使包装目标组件(例如 JTextArea)的 JScrollPane 自动向下滚动以显示最新的日志条目,请考虑调用:
to make the JScrollPane wrapping the target component (e.g. JTextArea) automatically scroll down to show the latest log entries, consider calling: