package com.example.demosentry.controller; import io.sentry.Sentry; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @Slf4j @RestController @RequestMapping("api") @Api(tags = "用户信息管理") public class DemoController { @ApiOperation("demo1") @GetMapping("demo1") public String demo1 () throws Exception{ //被动发送异常 int a = 0/0; return "demo1"; } @ApiOperation("demo2") @GetMapping("demo2") public String demo2 (){ //捕获的异常不会发送Sentry try{ throw new Exception("demo2 Exception"); }catch (Exception e){ } return "demo2"; } @ApiOperation("demo3") @GetMapping("demo3") public String demo3 (){ //主动推送捕获的异常,会发送Sentry try{ throw new Exception("demo3 Exception"); }catch (Exception e){ Sentry.captureException(e); } return "demo3"; } @ApiOperation("demo4") @GetMapping("demo4") public String demo4 (){ //info等级日志不会单独发送,需有error或Exception log.info("demo4 log info"); return "demo4"; } @ApiOperation("demo5") @GetMapping("demo5") public String demo5 (){ //error等级日志会发送 log.info("demo5 log info"); log.error("demo5 log error"); return "demo5"; } @ApiOperation("demo6") @GetMapping("demo6") public String demo6 (){ //异常时info日志也会发送 log.info("demo5 log info"); int a= 0/0; return "demo6"; } }2、Sentry查看结果 (1)总体结果
Demo2 异常没有被发送, Demo4的info日志没有被发送
info和error日志都发送过来了
异常时info日志也被发送了
server: port: 8001 sentry: dsn: http://项目的dsn logging: minimum-event-level: info minimum-breadcrumb-level: debug4、pom.xml
四、补充说明4.0.0 org.springframework.boot spring-boot-starter-parent2.5.8 com.example demo-sentry0.0.1-SNAPSHOT demo-sentry Demo project for Spring Boot 1.8 org.springframework.boot spring-boot-starter-weborg.springframework.boot spring-boot-starter-loggingorg.springframework.boot spring-boot-starter-log4j2org.projectlombok lomboktrue org.springframework.boot spring-boot-starter-testtest io.springfox springfox-boot-starter3.0.0 io.sentry sentry-spring-boot-starter5.5.2 io.sentry sentry-log4j25.5.2 org.springframework.boot spring-boot-maven-pluginorg.projectlombok lombok
页面上没有列出所有文档,更多官方文档需要检索得到,如:springboot
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)