log4j 自定义输出不同log文件(备忘)

分组输出:

log4j.rootLogger=INFO, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d - %m%n

log4j.logger.test2 =INFO, logfile2
log4j.appender.logfile2=org.apache.log4j.RollingFileAppender
log4j.appender.logfile2.File=userAction.log
log4j.appender.logfile2.MaxFileSize=512KB
# Keep three backup files.
log4j.appender.logfile2.MaxBackupIndex=3
# Pattern to output: date priority [category] - message
log4j.appender.logfile2.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile2.layout.ConversionPattern=%d - %m%n

log4j.logger.test1 =INFO,logfile1
log4j.appender.logfile1=org.apache.log4j.RollingFileAppender
log4j.appender.logfile1.File=VMInfo.log
log4j.appender.logfile1.MaxFileSize=512KB
# Keep three backup files.
log4j.appender.logfile1.MaxBackupIndex=3
# Pattern to output: date priority [category] - message
log4j.appender.logfile1.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile1.layout.ConversionPattern=%d - %m%n

 

 


   对应log4j.logger.test2

private static Logger logger = Logger.getLogger("test2");

 
  对应log.logger.test1

private static Logger logger = Logger.getLogger("test1");

 

 

不同级别输出到不同文件:

 

log4j.rootLogger=info,stdout,info,debug,error
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
……(补充)……

log4j.logger.info=info
log4j.appender.info=org.apache.log4j.RollingFileAppender
log4j.appender.info.File=info.log
……(补充)……

log4j.logger.debug=debug
log4j.appender.debug=org.apache.log4j.RollingFileAppender
log4j.appender.debug.File=debug.log
……(补充)……

log4j.logger.error=error
log4j.appender.error=org.apache.log4j.RollingFileAppender
log4j.appender.error.File=error.log
……(补充)……

 

你可能感兴趣的:(apache,log4j)