Log4J Swing Appender

心已入冬 提交于 2019-12-21 03:33:06

问题


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


回答1:


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.




回答2:


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




回答3:


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); 


来源:https://stackoverflow.com/questions/1358926/log4j-swing-appender

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!