SpringBoot Log4j2日志分级输出
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jeikerxiao/article/details/78140108
SpringBoot Log4j2日志分级输出
pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
application.properties
logging.config=classpath:log4j2.properties
- 1
log4j2.properties
分级输出不同级别的日志到不同文件中。
name=PropertiesConfig
property.filename=logs
appenders=console, Info, Error
# rootLogger
rootLogger.level=info
rootLogger.appenderRef.stdout.ref=Stdout
rootLogger.appenderRef.Info.ref=InfoRollingFile
rootLogger.appenderRef.Info.level=info
rootLogger.appenderRef.Error.ref=ErrorRollingFile
rootLogger.appenderRef.Error.level=error
# console
appender.console.type=Console
appender.console.name=Stdout
appender.console.layout.type=PatternLayout
appender.console.layout.pattern=%highlight{%d{MM-dd HH:mm:ss.SSS} [%5p] [%40.40c{1.}:%3L] - %m%n}{FATAL=white, ERROR=red, WARN=blue, INFO=Green, DEBUG=Yellow, TRACE=blue}
# info rolling file
appender.Info.type=RollingFile
appender.Info.name=InfoRollingFile
appender.Info.fileName=./logs/info.log
appender.Info.filePattern=./logs/info_%d{yyyy-MM-dd}_%i.log
appender.Info.layout.type=PatternLayout
appender.Info.layout.pattern=%highlight{%d{MM-dd HH:mm:ss.SSS} [%5p] [%40.40c{1.}:%3L] - %m%n}{FATAL=white, ERROR=red, WARN=blue, INFO=Green, DEBUG=Yellow, TRACE=blue}
appender.Info.policies.type=Policies
appender.Info.policies.time.type=TimeBasedTriggeringPolicy
appender.Info.policies.time.interval=1
appender.Info.policies.time.modulate=true
appender.Info.policies.size.type=SizeBasedTriggeringPolicy
appender.Info.policies.size.size=20M
appender.Info.strategy.type=DefaultRolloverStrategy
appender.Info.strategy.max=100
# error rolling file
appender.Error.type=RollingFile
appender.Error.name=ErrorRollingFile
appender.Error.fileName=./logs/error.log
appender.Error.filePattern=./logs/error_%d{yyyy-MM-dd}_%i.log
appender.Error.layout.type=PatternLayout
appender.Error.layout.pattern=%highlight{%d{MM-dd HH:mm:ss.SSS} [%5p] [%40.40c{1.}:%3L] - %m%n}{FATAL=white, ERROR=red, WARN=blue, INFO=Green, DEBUG=Yellow, TRACE=blue}
appender.Error.policies.type=Policies
appender.Error.policies.time.type=TimeBasedTriggeringPolicy
appender.Error.policies.time.interval=1
appender.Error.policies.time.modulate=true
appender.Error.policies.size.type=SizeBasedTriggeringPolicy
appender.Error.policies.size.size=20M
appender.Error.strategy.type=DefaultRolloverStrategy
appender.Error.strategy.max=100
转载请注明:SuperIT » SpringBoot Log4j2日志分级输出