forked from yudaocode/SpringBoot-Labs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
YunaiV
committed
Jan 5, 2020
1 parent
9046a6d
commit 9c61a28
Showing
6 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.2.2.RELEASE</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<packaging>jar</packaging> | ||
|
||
<artifactId>lab-39-logback</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.skywalking</groupId> | ||
<artifactId>apm-toolkit-logback-1.x</artifactId> | ||
<version>6.6.0</version> | ||
</dependency> | ||
|
||
<!-- 实现对 SpringMVC 的自动化配置 --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
13 changes: 13 additions & 0 deletions
13
...-logback/src/main/java/cn/iocoder/springboot/lab39/skywalkingdemo/LogbackApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package cn.iocoder.springboot.lab39.skywalkingdemo; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class LogbackApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(LogbackApplication.class, args); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...k/src/main/java/cn/iocoder/springboot/lab39/skywalkingdemo/controller/DemoController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package cn.iocoder.springboot.lab39.skywalkingdemo.controller; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/demo") | ||
public class DemoController { | ||
|
||
private Logger logger = LoggerFactory.getLogger(getClass()); | ||
|
||
@GetMapping("/logback") | ||
public String echo() { | ||
logger.info("测试日志"); | ||
return "logback"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
server: | ||
port: 8079 | ||
|
||
spring: | ||
application: | ||
name: demo-application-logback |
46 changes: 46 additions & 0 deletions
46
lab-39/lab-39-logback/src/main/resources/logback-spring.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<configuration> | ||
|
||
<!-- 引入 Spring Boot 默认的 logback XML 配置文件 --> | ||
<include resource="org/springframework/boot/logging/logback/defaults.xml"/> | ||
|
||
<!-- 控制台 Appender --> | ||
<property name="CONSOLE_LOG_X_PATTERN" value="%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %tid %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"/> | ||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender"> | ||
<!-- 日志的格式化 --> | ||
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> | ||
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout"> | ||
<Pattern>${CONSOLE_LOG_X_PATTERN}</Pattern> | ||
</layout> | ||
</encoder> | ||
</appender> | ||
|
||
<!-- 从 Spring Boot 配置文件中,读取 spring.application.name 应用名 --> | ||
<springProperty name="applicationName" scope="context" source="spring.application.name" /> | ||
<property name="FILE_LOG_PATTERN" value="%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}} ${LOG_LEVEL_PATTERN:-%5p} ${PID:- } %tid --- [%t] %-40.40logger{39} : %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"/> | ||
<!-- 日志文件的路径 --> | ||
<property name="LOG_FILE" value="/Users/yunai/logs/${applicationName}.log"/> | ||
<!-- 日志文件 Appender --> | ||
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender"> | ||
<file>${LOG_FILE}</file> | ||
<!--滚动策略,基于时间 + 大小的分包策略 --> | ||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> | ||
<fileNamePattern>${LOG_FILE}.%d{yyyy-MM-dd}.%i.gz</fileNamePattern> | ||
<maxHistory>7</maxHistory> | ||
<maxFileSize>10MB</maxFileSize> | ||
</rollingPolicy> | ||
<!-- 日志的格式化 --> | ||
<encoder> | ||
<pattern>${FILE_LOG_PATTERN}</pattern> | ||
<charset>utf8</charset> | ||
</encoder> | ||
</appender> | ||
|
||
<!-- 设置 Appender --> | ||
<root level="INFO"> | ||
<appender-ref ref="console"/> | ||
<appender-ref ref="file"/> | ||
</root> | ||
|
||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters