log4j简单例子

log4j简单例子
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 -(:%L)%n

log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=c:\\testsocket_log.log
log4j.appender.R.MaxFileSize=100KB
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} [%c]-[%p] %m -(:%L)%n



java简单代码:

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

public class Log4jTest {


public static void main(String[] args) {
  // TODO Auto-generated method stub
  String path="D:\\workspace\\test\\src\\log4j.properties";
  org.apache.log4j.PropertyConfigurator.configure(path);
  Logger logger = Logger.getLogger(Log4jTest.class);
  logger.debug("a test.");
}

}

你可能感兴趣的:(apache,C++,c,log4j,C#)