log4j配置文件样本
基本配置
属性文件方式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
log4j.rootLogger=INFO, Console,File log4j.logger.cc.gmem.demo=INFO log4j.appender.Console=org.apache.log4j.ConsoleAppender log4j.appender.Console.layout=org.apache.log4j.PatternLayout log4j.appender.Console.layout.ConversionPattern=[%-5p] [%t] %d{yyyy-MM-dd HH:mm:ss} %l%n%m%n log4j.appender.File=org.apache.log4j.RollingFileAppender log4j.appender.File.File=c:/logs/demo.log log4j.appender.File.Append=true log4j.appender.File.Threshold=ERROR log4j.appender.File.MaxFileSize=256MB log4j.appender.File.MaxBackupIndex=100 log4j.appender.File.layout=org.apache.log4j.PatternLayout log4j.appender.File.layout.ConversionPattern=[%-5p] [%t] %d{yyyy-MM-dd HH:mm:ss} %l%n%m%n |
layout
json
依赖于该项目:https://git.gmem.cc/alex/log4j-json-layout
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <appender name="console" class="org.apache.log4j.ConsoleAppender"> <param name="Target" value="System.out"/> <layout class="org.jetbrains.appenders.JsonLayout"> <param name="excludedFields" value="host,@version" /> </layout> </appender> <category name="cc.gmem"> <priority value="debug"/> </category> <root> <priority value="info"/> <appender-ref ref="console"/> </root> </log4j:configuration> |
Leave a Reply