package testLog;

import org.apache.log4j.Logger;

public class TestLog {
    public static void main(String[] args) {
         Logger logger = Logger.getLogger(TestLog.class);
          try {
                  logger.debug("设置教员的编号。");//使用Logger对象的debug、info方法输出日志信息
              } catch (IllegalArgumentException ex) {
                  logger.info("这是我的测试");
                  logger.info(ex.getMessage());//使用Logger对象的debug、info方法输出日志信息
               }
            
    }
}


log4j.properties配置文件

log4j.rootLogger=DEBUG,CONSOLE,A1,R,FILE1,FILE2,FILE3

log4j.addivity.org.apache=true  

# \u5E94\u7528\u4E8E\u63A7\u5236\u53F0  

log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender  

log4j.appender.CONSOLE.Threshold=INFO,debug

log4j.appender.CONSOLE.Target=System.out  

log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout  

log4j.appender.CONSOLE.layout.ConversionPattern=[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n  

# \u6BCF\u5929\u65B0\u5EFA\u65E5\u5FD7  

log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender  

log4j.appender.A1.File=C\:/log4j.log  

log4j.appender.A1.Threshold=DEBUG  

log4j.appender.A1.DatePattern='.'yyyy-MM-dd  

log4j.appender.A1.layout=org.apache.log4j.PatternLayout  

log4j.appender.A1.layout.ConversionPattern=%d{ABSOLUTE}  %5p %c{1}\:%L \: %m%n  


log4j.appender.R=org.apache.log4j.DailyRollingFileAppender

#\u6BCF\u5929\u8F93\u51FA\u4E00\u4E2A\u65E5\u5FD7\u6587\u4EF6

log4j.appender.R.DatePattern='_'yyyy-MM-dd'.log'

#\u6628\u5929\u7684\u65E5\u5FD7\u6587\u4EF6\u540DSendmsg+\u201C\u6628\u5929\u65E5\u671F\u201D.log

log4j.appender.R.File=C\:/log4j/debusssssg.log  

#\u65E5\u5FD7\u6587\u4EF6\u7684\u8DEF\u5F84\uFF0C${catalina.home} \u5373Tomcat\u4E0B

log4j.appender.R.layout=org.apache.log4j.HTMLLayout  

#\u65E5\u5FD7\u6587\u4EF6\u8F93\u51FA\u683C\u5F0F  

log4j.appender.R.layout.ConversionPattern=[framework]  %d - %c -%-4r [%t] %-5p %c %x - %m%n  

#\u5E94\u7528\u4E8E\u6587\u4EF6 (\u8C03\u8BD5\u6587\u4EF6)

log4j.appender.FILE1=org.apache.log4j.FileAppender  

log4j.appender.FILE1.File=C\:/log4j/debug.log  

log4j.appender.FILE1.Threshold=DEBUG

log4j.appender.FILE1.Append=true

log4j.appender.FILE1.layout=org.apache.log4j.PatternLayout  

log4j.appender.FILE1.layout.ConversionPattern=[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n  

 
#\u5E94\u7528\u4E8E\u6587\u4EF6 (INFO\u6587\u4EF6)

log4j.appender.FILE2=org.apache.log4j.FileAppender  

log4j.appender.FILE2.File=C\:/log4j/INFO.log  

log4j.appender.FILE2.Threshold=INFO

log4j.appender.FILE2.Append=true

log4j.appender.FILE2.layout=org.apache.log4j.PatternLayout  

log4j.appender.FILE2.layout.ConversionPattern=[framework] %d - %c  -%-4r [%t] %-5p %c %x - %m%n  

#\u5E94\u7528\u4E8E\u6587\u4EF6 (\u9519\u8BEF\u6587\u4EF6)

log4j.appender.FILE3=org.apache.log4j.FileAppender  

log4j.appender.FILE3.File=C\:/log4j/error.log  

log4j.appender.FILE3.Threshold=ERROR

log4j.appender.FILE3.Append=false  

log4j.appender.FILE3.layout=org.apache.log4j.PatternLayout  

log4j.appender.FILE3.layout.ConversionPattern=[framework] %d - %c  -%-4r [%t] %-5p %c %x - %m%n





转自:http://hi.baidu.com/jqetnwjnxuhquwr/item/6dbe9faea737a39f1410731c