log4j.properties模板

#http://logging.apache.org/log4j/1.2/manual.htmlhtml

#http://logging.apache.org/log4j/1.2/apidocs/index.htmlmysql

#DEBUG < INFO < WARN < ERROR < FATALsql


#日誌輸出路徑數據庫

log4j.logSaveDir=logsapache


#開啓log4j配置時的debugapi

log4j.debug=trueapp

#頂級Loggeride

log4j.rootLogger=DEBUG,Console.net

#,File,DailyRollingFile,RollingFile,Mail,Socket,DataBase,MyLoggerdebug


#設置slf4j.log4j包下日誌級別,及Logger

log4j.logger.slf4j.log4j=DEBUG,MyLogger

#是否在slf4j.log4j配置的logger輸出後,再啓用上級logger進行輸出

log4j.additivity.slf4j.log4j=false


#設置slf4j.log4j2包下日誌級別

log4j.logger.slf4j.log4j2=info 


#全局日誌級別過濾器

log4j.threshold=DEBUG



log4j.appender.MyLogger=org.apache.log4j.ConsoleAppender

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

log4j.appender.MyLogger.layout.ConversionPattern=[%t] %d{yyyy-MM-dd HH:mm:ss,SSS} [%r] [%-5p] [%c{2}] - [%m] [%l]%n 

log4j.appender.MyLogger.Threshold=DEBUG

#log4j.appender.MyLogger.filter.DenyAll=org.apache.log4j.varia.DenyAllFilter



#ConsoleAppender - 控制檯

log4j.logger.Console=DEBUG

log4j.appender.Console=org.apache.log4j.ConsoleAppender

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

log4j.appender.Console.layout.ConversionPattern=[%t] %d{yyyy-MM-dd HH:mm:ss,SSS} [%r] [%-5p] [%c{2}] - [%m] [%l]%n 

log4j.appender.Console.Threshold=DEBUG


#Filter↓↓↓

#DenyAllFilter 過濾掉全部

#LevelMatchFilter 日誌匹配過濾

#LevelRangeFilter 日誌區間過濾,區間外的首先會被過濾掉(LevelRangeFilter.decide),區間內的即便AcceptOnMatch爲true,也返回Filter.NEUTRAL

#StringMatchFilter 將message與指定字符串匹配(只是簡單的包含匹配,不支持正則啊,有須要的本身擴展下)

#log4j.appender.Console.filter.DenyAll=org.apache.log4j.varia.DenyAllFilter


#log4j.appender.Console.filter.LevelMatch=org.apache.log4j.varia.LevelMatchFilter

#log4j.appender.Console.filter.LevelMatch.LevelToMatch=ERROR

#log4j.appender.Console.filter.LevelMatch.AcceptOnMatch=false


#log4j.appender.Console.filter.StringMatch=org.apache.log4j.varia.StringMatchFilter

#log4j.appender.Console.filter.StringMatch.StringToMatch=hello

#log4j.appender.Console.filter.StringMatch.AcceptOnMatch=false



#log4j.appender.Console.filter.MyFilter=slf4j.log4j.MyFilter

#Filter↑↑↑


#FileAppender - 文件

log4j.appender.File=org.apache.log4j.FileAppender

log4j.appender.File.File=${log4j.logSaveDir}/log4j_FileAppender.log

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

log4j.appender.File.layout.ConversionPattern=[%t] %d{yyyy-MM-dd HH:mm:ss,SSS} [%r] [%-5p] [%c{2}] - [%m] [%l]%n



#DailyRollingFileAppender - 天天一個日誌文件,在每日結束時將日誌文件重命名

log4j.appender.DailyRollingFile=org.apache.log4j.DailyRollingFileAppender

log4j.appender.DailyRollingFile.File=${log4j.logSaveDir}/log4j_DailyRollingFileAppender.log

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

log4j.appender.DailyRollingFile.layout.ConversionPattern=[%t] %d{yyyy-MM-dd HH:mm:ss,SSS} [%r] [%-5p] [%c{2}] - [%m] [%l]%n

log4j.appender.DailyRollingFile.DatePattern="'-'yyyy-MM-dd"



#RollingFileAppender - 大小到達指定尺寸的時候新建日誌文件

log4j.appender.RollingFile=org.apache.log4j.RollingFileAppender

log4j.appender.RollingFile.File=${log4j.logSaveDir}/log4j_RollingFileAppender.log

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

log4j.appender.RollingFile.layout.ConversionPattern=[%t] %d{yyyy-MM-dd HH:mm:ss,SSS} [%r] [%-5p] [%c{2}] - [%m] [%l]%n

log4j.appender.RollingFile.MaxBackupIndex=3

log4j.appender.RollingFile.MaxFileSize=2kb



#SocketAppender - Socket

log4j.appender.Socket=org.apache.log4j.net.SocketAppender

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

log4j.appender.Socket.layout.ConversionPattern=[%t] %d{yyyy-MM-dd HH:mm:ss,SSS} [%r] [%-5p] [%c{2}] - [%m] [%l]%n



#SMTPAppender - 郵件

log4j.appender.Mail=org.apache.log4j.net.SMTPAppender

log4j.appender.Mail.Threshold=DEBUG

log4j.appender.Mail.BufferSize=10

log4j.appender.Mail.From=yourMailAccount@163.com

log4j.appender.Mail.SMTPHost=smtp.163.com

log4j.appender.Mail.SMTPUsername=yourMailAccount@163.com

log4j.appender.Mail.SMTPPassword=yourMailPassword

log4j.appender.Mail.SMTPDebug=true

log4j.appender.Mail.Subject= log4J Message

log4j.appender.Mail.Bcc=anotherMailAccount@qq.com

log4j.appender.Mail.To=anotherMailAccount@qq.com

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

log4j.appender.Mail.layout.ConversionPattern=[%t] %d{yyyy-MM-dd HH:mm:ss,SSS} [%r] [%-5p] [%c{2}] - [%m] [%l]%n



#JDBCAppender - 數據庫

log4j.appender.DataBase.Threshold=DEBUG

log4j.appender.DataBase.DEBUG=true

log4j.appender.DataBase=org.apache.log4j.jdbc.JDBCAppender

log4j.appender.DataBase.URL=jdbc:mysql://localhost:3306/test

log4j.appender.DataBase.driver=com.mysql.jdbc.Driver

log4j.appender.DataBase.user=root

log4j.appender.DataBase.password=123

log4j.appender.DataBase.sql=INSERT INTO log4j_log(message) VALUES('[%t] %d{yyyy-MM-dd HH:mm:ss,SSS} [%r] [%-5p] [%c{2}] - [%m] [%l]') 

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

#建表語句

#CREATE TABLE `log4j_log` (`message` VARCHAR(512) NULL);

#未避免輸出每條日誌都要鏈接一次數據庫,建議重寫JDBCAppender

相關文章
相關標籤/搜索