mirror of
https://gitee.com/yudaocode/SpringBoot-Labs.git
synced 2026-09-03 05:53:54 +08:00
增加 CAT 入门
This commit is contained in:
@@ -17,7 +17,7 @@ public class DemoController {
|
||||
@GetMapping("/transaction")
|
||||
public String transaction() {
|
||||
// 创建 Transaction 对象
|
||||
Transaction t = Cat.newTransaction("URL", "pageName");
|
||||
Transaction t = Cat.newTransaction("URL", "/demo/transaction");
|
||||
try {
|
||||
// ... yourBusiness(); 业务逻辑
|
||||
|
||||
@@ -39,7 +39,7 @@ public class DemoController {
|
||||
@GetMapping("/event-01")
|
||||
public String event01() {
|
||||
// Cat.logEvent("URL.Server", "127.0.0.1");
|
||||
Cat.logEvent("URL.Server2", "127.0.0.1", Event.SUCCESS, "data");
|
||||
Cat.logEvent("URL.Server", "127.0.0.1", Event.SUCCESS, "data");
|
||||
return "success";
|
||||
}
|
||||
|
||||
|
||||
61
lab-61/lab-61-logback/pom.xml
Normal file
61
lab-61/lab-61-logback/pom.xml
Normal file
@@ -0,0 +1,61 @@
|
||||
<?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>
|
||||
<artifactId>lab-61</artifactId>
|
||||
<groupId>cn.iocoder.springboot.labs</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>lab-61-logback</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<spring.boot.version>2.2.4.RELEASE</spring.boot.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>${spring.boot.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<!-- 引入 SpringMVC 相关依赖,并实现对其的自动配置 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 引入 CAT 相关依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.dianping.cat</groupId>
|
||||
<artifactId>cat-client</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<!-- 引入私服,因为 CAT 依赖并没有发到 Maven 中央仓库 -->
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>central</id>
|
||||
<name>Maven2 Central Repository</name>
|
||||
<layout>default</layout>
|
||||
<url>http://repo1.maven.org/maven2</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>unidal.releases</id>
|
||||
<url>http://unidal.org/nexus/content/repositories/releases/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,13 @@
|
||||
package cn.iocoder.springboot.lab61.catdemo;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package cn.iocoder.springboot.lab61.catdemo.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("/logger")
|
||||
public class LoggerController {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@GetMapping("/error")
|
||||
public String error() {
|
||||
try {
|
||||
int result = 1 / 0;
|
||||
} catch (Throwable e) {
|
||||
logger.error("计算异常", e);
|
||||
}
|
||||
return "success";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
app.name=demo-application
|
||||
21
lab-61/lab-61-logback/src/main/resources/logback-spring.xml
Normal file
21
lab-61/lab-61-logback/src/main/resources/logback-spring.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<configuration>
|
||||
|
||||
<!-- 参考 -->
|
||||
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
|
||||
<property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}}/spring.log}"/>
|
||||
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
|
||||
<include resource="org/springframework/boot/logging/logback/file-appender.xml" />
|
||||
|
||||
<!-- 定义 Sentry Appender -->
|
||||
<appender name="CatAppender" class="com.dianping.cat.logback.CatLogbackAppender" />
|
||||
|
||||
<!-- 日志输出级别 -->
|
||||
<root level="INFO">
|
||||
<appender-ref ref="CONSOLE" />
|
||||
<appender-ref ref="FILE" />
|
||||
<appender-ref ref="CatAppender" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
||||
@@ -13,6 +13,7 @@
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>lab-61-demo</module>
|
||||
<module>lab-61-logback</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
|
||||
Reference in New Issue
Block a user