ComponentAppender .java
package log4gui.log4j;
import java.awt.*;
import java.util.Hashtable;
import javax.swing.*;
import javax.swing.text.*;
import org.apache.log4j.*;
import org.apache.log4j.spi.LoggingEvent;
/**
* 扩展AppenderSkeleton,实现append方法即可
*/
public class ComponentAppender extends AppenderSkeleton {
protected Component comp; //用来展现log信息的gui组件
protected int entries;
protected int maxEntries; //记录的最多显示数
public static Appender getAppender(String appenderName) {
return getAppender(appenderName, null);
}
public static Appender getAppender(String appenderName, String categoryName) {
Appender result = null;
Logger testcat;
if (categoryName != null) {
testcat = Logger.getLogger(categoryName);
if (testcat != null) {
result = testcat.getAppender(appenderName);
}
}
if (result == null) {
testcat = Logger.getRootLogger();
result = testcat.getAppender(appenderName);
}
return result;
}
public ComponentAppender() {
this(null);
}
public ComponentAppender(Component comp) {
this(comp, 1);
}
public ComponentAppender(Component comp, int maxEntries) {
MutableAttributeSet attSet;
this.entries = 0;
this.maxEntries = maxEntries;
setComponent(comp);
}
public Component getComponent() {