冰狐
2018-12-14 17:30:52浏览 1959
相关的概念
- Loggers 输出的日志级别
- Appenders 输出到哪里
- org.apache.log4j.ConsoleAppender 控制台
- org.apache.log4j.FileAppender 文件
- org.apache.log4j.DailyRollingFileAppender 每天产生一个文件
- Layouts 输出格式
- org.apache.log4j.HTMLLayout Html格式
- org.apache.log4j.PatternLayout 自定义格式
- org.apache.log4j.SimpleLayout 简单的输出格式
- org.apache.log4j.TTCCLayout 包含时间, 线程, 类别等信息
配置格式
log4j.rootLogger = 级别, appenderName1, appenderName2
log4j.appender.appenderName1 = 对应的类名
log4j.appender.appenderName1.选项 = 值
log4j.appender.appenderName1.layout = 对应的类名
log4j.appender.appenderName1.layout.选项 = 值
log4j.appender.appenderName2 = 对应的类名
log4j.appender.appenderName2.选项 = 值
log4j.appender.appenderName2.layout = 对应的类名
log4j.appender.appenderName3.layout.选项 = 值
配置实例
log4j.rootLogger = DEBUG,console,file
log4j.appender.console = org.apache.log4j.ConsoleAppender
log4j.appender.console.target = System.out
log4j.appender.console.layout = org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern = %d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.appender.file = org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.File = logs/log.log
log4j.appender.file.Append = true
log4j.appender.file.Threshold = Error
log4j.appender.file.layout = org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} %5p %c{1}:%L - %m%n