log4j的用法
1.导入
2.在src下新建log4j.properties,内容如下
log4j.rootLogger=DEBUG, A1 ,R
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-d{yyyy-MM-dd HH\:mm\:ss} [%c]-[%p] %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=D:\\Test_Log4j.log
log4j.appender.R.MaxFileSize=100KB log4j.appender.R.MaxBackupIndex=1
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
3.测试日志
public void TestLog()
{
logger=Logger.getLogger(article.class.getName());
PropertyConfigurator.configure(".\\src\\log4j.properties");
logger.info("Info "+article.class.getName()+"\t "+" \t param=aaaaaaaaaaaaaa");
//获取类的相应方法
logger.warn("Warn ...");
logger.error("Error ...");
}