您的位置:首页 > 编程语言 > Java开发

SpringBoot - 日志集成 Log4j2

2017-01-18 12:06 851 查看

Log4j2

引入log4j2 依赖,spring-boot-starter-log4j2

排除Springboot logging

针对特别其他的log日志兼容比如logback引入 log4j-1.2-api

排除logback

application.yml 中设置日志配置文件

build.gradle

dependencies {
compile('org.springframework.boot:spring-boot-starter-log4j2')
compile('org.apache.logging.log4j:log4j-1.2-api:'+ log4jAPIVersion)
}

configurations {
all*.exclude module: 'spring-boot-starter-logging'
all*.exclude module: 'logback-classic'
all*.exclude module: 'log4j-over-slf4j'
}


application.yml

logging:
config: classpath:log4j2-spring.xml


创建 log4j2-spring.xml

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<properties>
<property name="PATTERN">%d{yyyy-MM-dd HH:mm:ss.SSS} |-%-5level [%thread] %c [%L] -| %msg%n</property>
</properties>
<appenders>
<Console name="CONSOLE" target="system_out">
<PatternLayout pattern="${PATTERN}" />
</Console>
</appenders>
<loggers>
<root level="debug">
<appenderref ref="CONSOLE" />
</root>
</loggers>
</configuration>


更多集成参考springboot github

代码

代码请移步 Github参考地址

如有疑问请加公众号(K171),如果觉得对您有帮助请 github start

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: