Springboot logback日志配置、多环境配置
java1234
共 1827字,需浏览 4分钟
·
2020-10-18 10:20
点击上方蓝色字体,选择“标星公众号”
优质文章,第一时间送达
1、resources目录下新增 logback-spring.xml
1-1、logback-spring.xml配置内容如下:
"1.0" encoding="UTF-8"?>
"context" name="logPath" source="log.path"/>
"CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
UTF-8
"allLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
${logPath}/website-info.log
%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
UTF-8
"ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
${logPath}/%d{yyyy-MM, aux}/all.%d{yyyy-MM-dd}.%i.log.gz
64MB
15
"errorLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
${logPath}/website.log-error.log
%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
UTF-8
"ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
${logPath}/%d{yyyy-MM, aux}/error.%d{yyyy-MM-dd}.%i.log.gz
64MB
15
"ch.qos.logback.classic.filter.LevelFilter">
error
ACCEPT
DENY
"INFO">
"CONSOLE"/>
"allLog"/>
"errorLog"/>
"com.cs.mapper" level="debug">
"org.springframework.jdbc" level="debug">
2、修改 mybatis 日志实现类配置为slf4j
configuration:
log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl
3、application.yml 指定日志配置文件加载路径:
#logback自定义配置文件
logging:
config: classpath:logback-spring.xml
4、application-dev.yml配置路径,开发环境可通过配置WEBSITE_LOG_PATH环境变量来指定目录:
注意:配置WEBSITE_LOG_PATH 不生效时,试着重启IDEA开发工具
#日志路径
#注意:开发人员需配置本地日志输出路径的环境变量:WEBSITE_LOG_PATH,否则默认日志路径为:/Volumes/work/log/website
log:
path: ${WEBSITE_LOG_PATH:/Volumes/work/log/website}
5、application-test.yml配置路径
#日志路径
log:
path: /data/log/website
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:
https://blog.csdn.net/qq_23039185/article/details/109101379
感谢点赞支持下哈
评论