導包
1.commons-logging.jar包 下載
2.log4j.jar包 下載
配置log4j
1.在src根目錄下創建一個log4j.properties文件。
文件全部內容如下:
log4j.rootLogger=CONSOLE,stdout,logfile
#stdout控制器
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
#輸出格式
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c]:%L - %m%n
#文件路徑輸出
log4j.appender.logfile=org.apache.log4j.RollingFileAppender
log4j.appender.logfile.File=D:/keyservice.log
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n
#最多保存 log文件大小、
log4j.appender.logfile.Apppend=true
log4j.appender.logfile.MaxFileSize=11000kb
#最多保存
log4j.appender.logfile.MaxBackupIndex=10
log日誌文件輸出路徑可以改,我寫的是D:/keyservice.log。
調用時候在頭部聲明
public static Log log = LogFactory.getLog(你當前的類名.class);
log.info("xxxxxxxxxxx"):
log.debug("xxxxxxxxxxx"):
---------------------
作者:隔壁丶小王
來源:CSDN
原文:https://blog.csdn.net/qq_32691899/article/details/80263954
版權聲明:本文爲博主原創文章,轉載請附上博文鏈接!