2019-03-24 java log 配置多log文件记录

1java log 使用

先导入 jar 包 。

jar包下载地址:http://www.apache.org/dyn/closer.cgi/logging/log4j/1.2.17/log4j-1.2.17.zip

jar包下载

2配置log4j.properties

log4j.properties位置

设置了mylogger1,mylogger6,mylogger20。

![log4j.properties内容]
done.png


log4j.logger.mylogger1=DEBUG,test1

log4j.appender.test1=org.apache.log4j.FileAppender

log4j.appender.test1.File=C:/log/test1.log

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

log4j.appender.test1.layout.ConversionPattern=%m%n



log4j.logger.mylogger6=DEBUG,test6

log4j.appender.test6=org.apache.log4j.FileAppender

log4j.appender.test6.File=C:/log/test6.log

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

log4j.appender.test6.layout.ConversionPattern=%m%n



log4j.logger.mylogger20=DEBUG,test20

log4j.appender.test20=org.apache.log4j.FileAppender

log4j.appender.test20.File=C:/log/test20.log  

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

log4j.appender.test20.layout.ConversionPattern=%m%n

java文件
设置logger1,logger6,logger20是

    private static Log logger1 = LogFactory.getLog("mylogger1");
    private static Log logger6 = LogFactory.getLog("mylogger6");
    private static Log logger20 = LogFactory.getLog("mylogger20");

设置logger1,logger6,logger20输出到日志的内容

 
                logger1. debug("it is f" );  
 
                logger6. debug("it is 6" ); 
 
                logger20. debug("it is 20" ); 

你可能感兴趣的:(2019-03-24 java log 配置多log文件记录)