log4j全局设置和对于单个类的设置

 

 

import org.apache.log4j.Logger;
/**
 * 以下log显示在控制台
 * @author EX-SUNGEBING001
 *
 */
public class TestLog {
 public static void main(String argv[]) {
  Logger logger =Logger.getLogger("A3.");
  logger.debug("This is debug.");
  logger.info("This is an info.");
  logger.warn("This is a warning.");
  logger.error("This is an error.");
  logger.fatal("This is a fatal error.");
 }
}

---------------------------------------------------------------------------------------------------------------------------------------------

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
 * 以下log仅写入log文本
 * @author EX-SUNGEBING001
 *
 */
public class TestLog2 {
 public static void main(String argv[]) {
  Log logger =LogFactory.getLog(TestLog2.class);
  logger.debug("#####This is debug.");
  logger.info("#####This is an info.");
  logger.warn("#####This is a warning.");
  logger.error("#####This is an error.");
  logger.fatal("#####This is a fatal error.");
 }
}

---------------------------------------------------------------------------------------------------------------------------------------------

log4j.rootLogger=INFO

log4j.logger.TestLog2=DEBUG,A1,A3
#log4j.logger.TestLog2=DEBUG,A3

log4j.appender.A1=org.apache.log4j.RollingFileAppender
log4j.appender.A1.File=D:/convert.log
log4j.appender.A1.MaxFileSize=1000KB
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d %-5p [%t] %C{2} (%F:%L) - %m%n

log4j.appender.A3=org.apache.log4j.RollingFileAppender
log4j.appender.A3.File=D:/convert2.log
log4j.appender.A3.MaxFileSize=1000KB
log4j.appender.A3.layout=org.apache.log4j.PatternLayout
log4j.appender.A3.layout.ConversionPattern=%d %-5p [%t] %C{2} (%F:%L) - %m%n

log4j.appender.A2=org.apache.log4j.ConsoleAppender
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=%d %-5p [%t] %C{2} (%F:%L) - %m%n


log4j.logger.A2.TestLog2=INFO,A2
log4j.additivity.A2.TestLog2=false
###################
log4j.logger.A1.TestLog2=INFO,A1
log4j.additivity.A1.TestLog2=false
log4j.appender.A1.TestLog2=%d{yyyy-MM-dd HH\:mm\:ss.sss} [%t] %-5p %C{1} : %m%n
###################

 

 

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