Logger4j配置

1.把log4j.jar(一般是log4j-1.2.11这种名字的类型)导入工程.

2.在src下面新建log4j.properties.
写入下面内容
//全局默认的日志级别
log4j.rootLogger=INFO,stdout,rolling
//自己要定义的日志
log4j.logger.com.woogo.golf=ERROR, A1
   
//配置Appender,以下11句为子定义的logger
log4j.appender.A1=org.apache.log4j.RollingFileAppender
log4j.appender.A1.File=c\:mail.log
log4j.appender.A1.MaxFileSize=500KB
log4j.appender.A1.MaxBackupIndex=50
log4j.appender.A1.Append=true
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d{ISO8601} - [%p] [%C{1}] - %m%n
log4j.logger.com.woogo.util.MailSend=INFO,A1
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %r [%t] %5p [%F:%L] - %m%n

log4j.appender.rolling.layout=org.apache.log4j.PatternLayout
log4j.appender.rolling.layout.ConversionPattern=%d %r [%t] %5p [%F:%L] - %m%n
log4j.appender.rolling=org.apache.log4j.RollingFileAppender
log4j.appender.rolling.File=${user.dir}/log.log
#log4j.appender.rolling.File=/usr/local/jakarta-tomcat-5.0.25/logs/woogo.log
log4j.appender.rolling.MaxFileSize=5120KB
log4j.appender.rolling.MaxBackupIndex=10


3.测试类:
import org.apache.log4j.Logger;


public class Test {
public static final Logger log = Logger.getLogger(Test.class);

public static void main(String[] args) {
              log.info("kkk");
}
}
将会在src同级目录下的log.log文件和控制台同时看到info的内容为kkk.

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