分类:
2010-11-29 01:00:42
log4j.rootLogger=debug,R
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=.\\system.log
log4j.appender.R.MaxFileSize=100KB
# Keep one backup file
log4j.appender.R.MaxBackupIndex=1
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=[%d{yyyy-MM-dd HH:mm:ss,SSS}(%t)] %-5p %c -%m%n
#log4j.appender.R.layout.ConversionPattern=[%d{ISO8601}] %-5p %-x %X{user} ---- %m%n
static org.apache.log4j.Logger log = org.apache.log4j.Logger.getRootLogger();
org.apache.log4j.PropertyConfigurator.configure("log4j.inf");
[2003-11-16 16:45:06,218(AWT-EventQueue-0)] INFO root - LOG4J测试程序启动
package log4j;
import org.apache.log4j.*;
import org.apache.log4j.spi.*;
public class JTextAreaAppender extends AppenderSkeleton
{
javax.swing.JTextArea jText = null;
public JTextAreaAppender(Layout layout, javax.swing.JTextArea jText)
{
this.layout = layout;
this.jText = jText;
}
public JTextAreaAppender(javax.swing.JTextArea jText)
{
this.layout = new org.apache.log4j.PatternLayout("%p [%t] %c - %m%n");
this.jText = jText;
}
public void setJText(javax.swing.JTextArea jText)
{
this.jText = jText;
}
protected void append(LoggingEvent event)
{
if(this.jText == null)
return ;
this.subAppend(event);
}
public boolean requiresLayout()
{
return true;
}
public synchronized void close()
{
if (this.closed)
{
return;
}
this.closed = true;
}
public void subAppend(LoggingEvent event)
{
synchronized(jText)
{
this.jText.append(this.layout.format(event));
}
}
}
static org.apache.log4j.Logger log = org.apache.log4j.Logger.getRootLogger();
org.apache.log4j.PropertyConfigurator.configure("log4j.inf");
log.addAppender(new log4j.JTextAreaAppender(this.jTextArea1));