| @@ -0,0 +1,62 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |||||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | |||||
| <modelVersion>4.0.0</modelVersion> | |||||
| <parent> | |||||
| <groupId>org.springframework.boot</groupId> | |||||
| <artifactId>spring-boot-starter-parent</artifactId> | |||||
| <version>2.0.3.RELEASE</version> | |||||
| <relativePath/> <!-- lookup parent from repository --> | |||||
| </parent> | |||||
| <groupId>com.example</groupId> | |||||
| <artifactId>springBootDemo</artifactId> | |||||
| <version>0.0.1-SNAPSHOT</version> | |||||
| <name>springBootDemo</name> | |||||
| <description>Demo project for Spring Boot</description> | |||||
| <dependencies> | |||||
| <dependency> | |||||
| <groupId>org.springframework.boot</groupId> | |||||
| <artifactId>spring-boot-starter-web</artifactId> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>org.projectlombok</groupId> | |||||
| <artifactId>lombok</artifactId> | |||||
| <optional>true</optional> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>org.springframework.boot</groupId> | |||||
| <artifactId>spring-boot-starter-test</artifactId> | |||||
| <scope>test</scope> | |||||
| </dependency> | |||||
| <!-- <dependency>--> | |||||
| <!-- <groupId>de.codecentric</groupId>--> | |||||
| <!-- <artifactId>spring-boot-admin-starter-client</artifactId>--> | |||||
| <!-- <version>2.0.3</version>--> | |||||
| <!-- </dependency>--> | |||||
| <!-- <dependency>--> | |||||
| <!-- <groupId>org.springframework.boot</groupId>--> | |||||
| <!-- <artifactId>spring-boot-starter-actuator</artifactId>--> | |||||
| <!-- </dependency>--> | |||||
| </dependencies> | |||||
| <build> | |||||
| <plugins> | |||||
| <plugin> | |||||
| <groupId>org.springframework.boot</groupId> | |||||
| <artifactId>spring-boot-maven-plugin</artifactId> | |||||
| <configuration> | |||||
| <excludes> | |||||
| <exclude> | |||||
| <groupId>org.projectlombok</groupId> | |||||
| <artifactId>lombok</artifactId> | |||||
| </exclude> | |||||
| </excludes> | |||||
| </configuration> | |||||
| </plugin> | |||||
| </plugins> | |||||
| </build> | |||||
| </project> | |||||
| @@ -0,0 +1,13 @@ | |||||
| package com.example.springbootdemo; | |||||
| import org.springframework.boot.SpringApplication; | |||||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | |||||
| @SpringBootApplication | |||||
| public class SpringBootDemoApplication { | |||||
| public static void main(String[] args) { | |||||
| SpringApplication.run(SpringBootDemoApplication.class, args); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,25 @@ | |||||
| package com.example.springbootdemo.controller; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.web.bind.annotation.GetMapping; | |||||
| import org.springframework.web.bind.annotation.RestController; | |||||
| @RestController | |||||
| public class HelloController { | |||||
| private final Logger logger = LoggerFactory.getLogger(HelloController.class); | |||||
| @GetMapping("/") | |||||
| public String index() { | |||||
| logger.info("a log : Greetings from Spring Boot"); | |||||
| return "Greetings from Spring Boot!"; | |||||
| } | |||||
| @GetMapping("/healthcheck") | |||||
| public String healthcheck() { | |||||
| logger.error("a log : Call error"); | |||||
| return "Greetings from Spring Boot! Call error"; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,9 @@ | |||||
| server.port=8081 | |||||
| logging.config=classpath:logback-spring.xml | |||||
| log.path=logs | |||||
| # FALSE同步;FILE异步 | |||||
| log.async.file=FILE | |||||
| @@ -0,0 +1,76 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <configuration> | |||||
| <springProperty scope="context" name="logPath" source="log.path"/> | |||||
| <springProperty scope="context" name="isAsync" source="log.async.file"/> | |||||
| <property name="logPattern" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger-%msg%n"/> | |||||
| <!-- 标准输出 --> | |||||
| <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | |||||
| <encoder> | |||||
| <pattern>${logPattern}</pattern> | |||||
| </encoder> | |||||
| </appender> | |||||
| <appender name="FALSE" class="ch.qos.logback.core.rolling.RollingFileAppender"> | |||||
| </appender> | |||||
| <!-- 日志按天生成 --> | |||||
| <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> | |||||
| <encoder> | |||||
| <pattern>${logPattern}</pattern> | |||||
| <charset>UTF-8</charset> | |||||
| </encoder> | |||||
| <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> | |||||
| <fileNamePattern>${logPath}/demolog.%d{yyyy-MM-dd}-%i.log</fileNamePattern> | |||||
| <maxHistory>7</maxHistory> | |||||
| <maxFileSize>100MB</maxFileSize> | |||||
| <totalSizeCap>1GB</totalSizeCap> | |||||
| </rollingPolicy> | |||||
| <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> | |||||
| <level>ERROR</level> | |||||
| </filter> | |||||
| </appender> | |||||
| <!-- 异步输出 --> | |||||
| <appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender"> | |||||
| <!-- 默认如果队列的80%已满,则会丢弃TRACT、DEBUG、INFO级别的日志,若要保留全部日志,设置为0 --> | |||||
| <discardingThreshold>0</discardingThreshold> | |||||
| <!-- 更改默认的队列的深度,该值会影响性能.默认值为256 --> | |||||
| <queueSize>512</queueSize> | |||||
| <!-- 往队列添加时,是否block,默认false[blockingQueue.put],当队列满了后需要等待;如果设为true[blockingQueue.offer],不等待,直接丢弃数据 --> | |||||
| <neverBlock>false</neverBlock> | |||||
| <!--是否打印调用方信息--> | |||||
| <includeCallerData>false</includeCallerData> | |||||
| <!-- 添加附加的appender,最多只能添加一个 --> | |||||
| <appender-ref ref="${isAsync}"/> | |||||
| </appender> | |||||
| <!-- 错误日志单独再记录,以便当前的日志分析报警 --> | |||||
| <!-- <appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">--> | |||||
| <!-- <filter class="ch.qos.logback.classic.filter.ThresholdFilter">--> | |||||
| <!-- <level>ERROR</level>--> | |||||
| <!-- </filter>--> | |||||
| <!-- <encoder>--> | |||||
| <!-- <pattern>${logPattern}</pattern>--> | |||||
| <!-- </encoder>--> | |||||
| <!-- <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">--> | |||||
| <!-- <fileNamePattern>${logPath}/error.%d{yyyy-MM-dd}.log</fileNamePattern>--> | |||||
| <!-- <maxHistory>7</maxHistory>--> | |||||
| <!-- </rollingPolicy>--> | |||||
| <!-- </appender>--> | |||||
| <!-- 屏蔽框架输出 --> | |||||
| <!-- <logger name="ch.qos.logback" level="OFF"/>--> | |||||
| <!-- <logger name="org.apache.ibatis" level="INFO"/>--> | |||||
| <!-- <logger name="tk.mybatis.mapper" level="INFO"/>--> | |||||
| <!-- <logger name="org.mybatis.spring" level="INFO"/>--> | |||||
| <root> | |||||
| <level value="INFO"/> | |||||
| <appender-ref ref="FILE"/> | |||||
| <!-- <appender-ref ref="error"/>--> | |||||
| <appender-ref ref="STDOUT"/> | |||||
| </root> | |||||
| </configuration> | |||||
| @@ -0,0 +1,13 @@ | |||||
| package com.example.springbootdemo; | |||||
| import org.junit.Test; | |||||
| import org.springframework.boot.test.context.SpringBootTest; | |||||
| @SpringBootTest | |||||
| class SpringBootDemoApplicationTests { | |||||
| @Test | |||||
| void contextLoads() { | |||||
| } | |||||
| } | |||||