一:配置logback-spring.xml文件,文件名为默认,自定义需要自己引入
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<!-- logback-spring.xml文件读取优先于application.yml,不能直接读取,用springProperty-->
<springProperty scope="context" name="logPath" source="logging.file.path"/>
<appender name="consoleLog" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>
%date{yyyy-MM-dd HH:mm:ss.SSS} %-5level[%thread]%logger{56}.%method:%L -%msg%n
</pattern>
</layout>
</appender>
<appender name="fileInfoLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!--INFO日志中包含INFO以上的错误信息-->
<level>INFO</level>
<!--INFO日志过滤错误日志下面配置-->
<!--<level>ERROR</level>-->
<!--<onMatch>DENY</onMatch>-->
<!--<onMismatch>ACCEPT</onMismatch>-->
</filter>
<encoder>
<pattern>
%date{yyyy-MM-dd HH:mm:ss.SSS} %-5level[%thread]%logger{56}.%method:%L -%msg%n
</pattern>
</encoder>
<!--滚动策略-->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--路径-->
<fileNamePattern>${logPath}/IndustryInfo.%d{yyyy-MM-dd}.log</fileNamePattern>
</rollingPolicy>
</appender>
<appender name="fileErrorLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level>
</filter>
<encoder>
<pattern>
%date{yyyy-MM-dd HH:mm:ss.SSS} %-5level[%thread]%logger{56}.%method:%L -%msg%n
</pattern>
</encoder>
<!--滚动策略-->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--路径-->
<fileNamePattern>${logPath}/IndustryError.%d{yyyy-MM-dd}.log</fileNamePattern>
</rollingPolicy>
</appender>
<root level="INFO">
<appender-ref ref="consoleLog"/>
<appender-ref ref="fileInfoLog"/>
<appender-ref ref="fileErrorLog"/>
</root>
</configuration>
二:各个环境的日志的输入位置可能不同,进行如下配置:
application.yml
spring:
profiles:
# 环境分支:dev本地分支|test测试分支|prod生产分支
active: test
# 配置pagehelper参数
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
application-test.yml
#用于配置开发坏境信息
#配置服务端口号 8085映射外网端口:9100
server:
port: 8085
servlet:
context-path: /industry
session:
timeout: 1800s
# 配置数据库信息
spring:
datasource:
url: jdbc:mysql://192.168.1.28:3306/industryinfotrace?useUnicode=true&characterEncoding=utf-8
username: root
password: rfidtc
driver-class-name: com.mysql.jdbc.Driver
#Mybatis的mapper.xml文件位置
mybatis:
mapper-locations: classpath:mapper/*.xml
#配置日志输出位置
logging:
file:
path: /home/logs/
如果本地共用的话,没有的话,为C盘下的home文件夹下面的logs文件件