Skip to content

Commit

Permalink
修改配置文件和新增log日志
Browse files Browse the repository at this point in the history
  • Loading branch information
bonjour520 committed Dec 4, 2018
1 parent 72b3398 commit 06d185a
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 14 deletions.
20 changes: 10 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,16 @@
</dependency>

<!-- swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>



Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/lanceyi/small/SmallApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
@SpringBootApplication
@MapperScan("com.lanceyi.small")
public class SmallApplication {

public static void main(String[] args) {
SpringApplication.run(SmallApplication.class, args);
}
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/com/lanceyi/small/controller/TestController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@

import com.lanceyi.small.base.SuccessResponseTemplate;
import com.lanceyi.small.config.Path;
import com.lanceyi.small.dto.response.TestResponse;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
* @author Lance YI
* @date 2018/12/4 10:01
Expand All @@ -15,9 +18,12 @@
@RestController
public class TestController {

@ApiOperation("测试hello")
@ApiOperation("测试")
@GetMapping(Path.Test.BASE)
public SuccessResponseTemplate hello(){
return SuccessResponseTemplate.ok("hello");
public SuccessResponseTemplate<List<TestResponse>> hello(){
TestResponse testResponse = new TestResponse();
testResponse.setFirstName("Yi");
testResponse.setLastName("Lance");
return SuccessResponseTemplate.ok(testResponse);
}
}
18 changes: 18 additions & 0 deletions src/main/java/com/lanceyi/small/dto/response/TestResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.lanceyi.small.dto.response;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
* @author Lance YI
* @date 2018/12/4 16:58
*/
@Data
public class TestResponse {
@ApiModelProperty("姓")
private String firstName;

@ApiModelProperty("名")
private String lastName;

}
48 changes: 48 additions & 0 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
server:
port: 8080

spring:
datasource:
druid:
# jdbc
url: jdbc:mysql://192.168.1.8:3306/runmin?useUnicode=true&characterEncoding=utf8
username: root
password: s123456
driver-class-name: com.mysql.jdbc.Driver
# 连接池
# 初始化连接数
initial-size: 1
# 最大连接数量
max-active: 3000
# 最小空闲数量
min-idle: 5
# 最大连接等待超时时长
max-wait: 70000
# 检测配置
validation-query: select 1
validation-query-timeout: 20
test-while-idle: true
test-on-borrow: false
test-on-return: false

redis:
host: 192.168.1.3
password: s123456
jedis:
pool:
max-active: 100
max-idle: 10
min-idle: 1

mvc:
# 404 抛出错误
throw-exception-if-no-handler-found: true

mybatis:
# 实体对象所在的包
typeAliasesPackage: com.lanceyi.small.model
# mapper所在的位置
mapper-locations: classpath:mappers/*.xml
#驼峰映射
configuration:
mapUnderscoreToCamelCase: true
4 changes: 4 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ spring:
test-while-idle: true
test-on-borrow: false
test-on-return: false
profiles:
active: dev


redis:
host: 192.168.1.3
Expand All @@ -46,3 +49,4 @@ mybatis:
#驼峰映射
configuration:
mapUnderscoreToCamelCase: true

78 changes: 78 additions & 0 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- 日志配置 参考:https://springframework.guru/using-logback-spring-boot/ -->
<configuration>

<!-- 引用spring boot 默认配置,主要是用默认的控制台输出配置-->
<include resource="org/springframework/boot/logging/logback/base.xml"/>

<!-- 读取spring属性 -->
<springProperty scope="context" name="appName" source="spring.application.name"/>

<!-- 每天产生一个日志文件,超过大小自动分割 -->
<appender name="all_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">

<FileNamePattern>/logs/${appName}/all-info-%d{yyyy-MM-dd}-%i.log</FileNamePattern>
<MaxHistory>30</MaxHistory>

<!-- 按时间回滚的同时,按文件大小来回滚 -->
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>

</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%date{yyyy-MM-dd HH:mm:ss.SSS} %-5level %-4L--- [%15.15t] %-50.50logger : %msg%n</pattern>
</encoder>

</appender>

<appender name="all_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>/logs/${appName}/error-%d{yyyy-MM-dd}-%i.log</FileNamePattern>
<!--日志文件保留天数-->
<MaxHistory>30</MaxHistory>
<TimeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<MaxFileSize>100MB</MaxFileSize>
</TimeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%date{yyyy-MM-dd HH:mm:ss.SSS} %-5level %-4L--- [%15.15t] %-50.50logger : %msg%n</pattern>
</encoder>
</appender>


<springProfile name="dev">
<root level="INFO">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="all_info"/>
<appender-ref ref="all_error"/>
</root>
</springProfile>

<springProfile name="test">
<root level="INFO">
<appender-ref ref="all_info"/>
<appender-ref ref="all_error"/>
</root>
</springProfile>

<springProfile name="prod">
<root level="INFO">
<appender-ref ref="all_info"/>
<appender-ref ref="all_error"/>
</root>
</springProfile>


</configuration>

0 comments on commit 06d185a

Please sign in to comment.