log4j配置文件详解及其举例用法
#①配置根Logger,其语法为:
#
#log4j.rootLogger = [level],appenderName,appenderName2,...
#level
##Log4j
#
#
#appenderName
################################################################################
#
#
#Log4j
#1)org.apache.log4j.ConsoleAppender(
#2)org.apache.log4j.FileAppender(
#3)org.apache.log4j.DailyRollingFileAppender
#4)org.apache.log4j.RollingFileAppender(
#5)org.apache.log4j.WriterAppender(
#
#1)ConsoleAppender
# -Threshold = DEBUG:
# -ImmediateFlush = TRUE:
# -Target = System.err
#
#2)FileAppender
# -Threshold = INFO:
# -ImmediateFlush = TRUE:
# -File = C:\log4j.log:
# -Append = FALSE:
# -Encoding = UTF-8:
#
#3)DailyRollingFileAppender
# -Threshold = WARN:
# -ImmediateFlush = TRUE:
# -File = C:\log4j.log:
# -Append = FALSE:
# -DatePattern='.'yyyy-ww:
#
#
#
#
#
#
# -Encoding = UTF-8:
#
#4)RollingFileAppender
# -Threshold = ERROR:
# -ImmediateFlush = TRUE:
# -File = C:/log4j.log:
# -Append = FALSE:
# -MaxFileSize = 100KB:
# -MaxBackupIndex = 2:
# -Encoding = UTF-8:
################################################################################
################################################################################
#
#
#log4j.appender.appenderName.layout = fully.qualified.name.of.layout.class
#log4j.appender.appenderName.layout.optionN = valueN
#
#Log4j
#5)org.apache.log4j.HTMLLayout(
#6)org.apache.log4j.PatternLayout(
#7)org.apache.log4j.SimpleLayout(
#8)org.apache.log4j.TTCCLayout(
#9)org.apache.log4j.xml.XMLLayout(
#
#5)HTMLLayout
# -LocationInfo = TRUE:
# -Title=Struts Log Message:
#
#6)PatternLayout
# -ConversionPattern = %m%n:
#
#9)XMLLayout
# -LocationInfo = TRUE:
#
#Log4J
# %m
# %p
# %r
# %c
# %t
# %n
# %d
#
# %l
#
# %F
# %L
# %x
# %%
#
#
#
#
#
#
################################################################################
################################################################################
#
#log4j.logger.org.springframework=DEBUG
################################################################################
#OFF,systemOut,logFile,logDailyFile,logRollingFile,logMail,logDB,ALL
log4j.rootLogger =ALL,systemOut,logFile,logDailyFile,logRollingFile,logMail,logDB
#
log4j.appender.systemOut =
log4j.appender.systemOut.layout =
log4j.appender.systemOut.layout.ConversionPattern =
log4j.appender.systemOut.Threshold =
log4j.appender.systemOut.ImmediateFlush =
log4j.appender.systemOut.Target =
#
log4j.appender.logFile =
log4j.appender.logFile.layout =
log4j.appender.logFile.layout.ConversionPattern =
log4j.appender.logFile.Threshold =
log4j.appender.logFile.ImmediateFlush =
log4j.appender.logFile.Append =
log4j.appender.logFile.File =
log4j.appender.logFile.Encoding =
#
log4j.appender.logDailyFile =
log4j.appender.logDailyFile.layout =
log4j.appender.logDailyFile.layout.ConversionPattern =
log4j.appender.logDailyFile.Threshold =
log4j.appender.logDailyFile.ImmediateFlush =
log4j.appender.logDailyFile.Append =
log4j.appender.logDailyFile.File =
log4j.appender.logDailyFile.DatePattern =
log4j.appender.logDailyFile.Encoding =
#
log4j.appender.logRollingFile =
log4j.appender.logRollingFile.layout =
log4j.appender.logRollingFile.layout.ConversionPattern =
log4j.appender.logRollingFile.Threshold =
log4j.appender.logRollingFile.ImmediateFlush =
log4j.appender.logRollingFile.Append =
log4j.appender.logRollingFile.File =
log4j.appender.logRollingFile.MaxFileSize =
log4j.appender.logRollingFile.MaxBackupIndex =
log4j.appender.logRollingFile.Encoding =
#
log4j.appender.logMail =
log4j.appender.logMail.layout =
log4j.appender.logMail.layout.LocationInfo =
log4j.appender.logMail.layout.Title =
log4j.appender.logMail.Threshold =
log4j.appender.logMail.SMTPDebug =
log4j.appender.logMail.SMTPHost =
log4j.appender.logMail.From =
log4j.appender.logMail.To =
#log4j.appender.logMail.Cc = xly3000@gmail.com
#log4j.appender.logMail.Bcc = xly3000@gmail.com
log4j.appender.logMail.SMTPUsername =
log4j.appender.logMail.SMTPPassword =
log4j.appender.logMail.Subject =
#log4j.appender.logMail.BufferSize = 1024
#log4j.appender.logMail.SMTPAuth = TRUE
#
log4j.appender.logDB =
log4j.appender.logDB.layout =
log4j.appender.logDB.Driver =
log4j.appender.logDB.URL =
log4j.appender.logDB.User =
log4j.appender.logDB.Password =
log4j.appender.logDB.Sql =
log4j目录路径的设置
log4j.appender.R1.File=/log.log -->>这种输出到 盘的 根目录下 (不推荐,win和linux 不同)
log4j.appender.R1.File=logs/ydcardsys.log -->>项目文件中 (不推荐,容易清理掉)
log4j.appender.R.File=${catalina.home}/logs/ydbudget.log (tomcat系的容器 这种方法不错,切到别的容器就不行了)
web.xml
<context-param> <param-name>webAppRootKey</param-name> <param-value>webApp.root</param-value> </context-param>
log4j.appender.R1.File=${webApp.root}logs/log.log