aop - logback, sentry
This commit is contained in:
6
aop/logs/logback.log
Normal file
6
aop/logs/logback.log
Normal file
@@ -0,0 +1,6 @@
|
||||
[2021-02-03 02:15:40:12333][http-nio-8080-exec-1] WARN c.example.aop.config.BindingAdvice - com.example.aop.web.UserController.save() => 필드 : username, 메시지 : 유저네임을 입력하세요.
|
||||
[2021-02-03 02:22:00:7788][http-nio-8080-exec-1] WARN c.example.aop.config.BindingAdvice - com.example.aop.web.UserController.save() => 필드 : username, 메시지 : 유저네임을 입력하세요.
|
||||
[2021-02-03 02:22:58:7566][http-nio-8080-exec-3] WARN c.example.aop.config.BindingAdvice - com.example.aop.web.UserController.save() => 필드 : username, 메시지 : 유저네임을 입력하세요.
|
||||
[2021-02-03 02:27:20:17752][http-nio-8080-exec-1] WARN c.example.aop.config.BindingAdvice - com.example.aop.web.UserController.save() => 필드 : username, 메시지 : 유저네임을 입력하세요.
|
||||
[2021-02-03 02:43:31:15646][http-nio-8080-exec-1] WARN c.example.aop.config.BindingAdvice - com.example.aop.web.UserController.save() => 필드 : username, 메시지 : 유저네임을 입력하세요.
|
||||
[2021-02-03 02:43:46:30108][http-nio-8080-exec-2] WARN c.example.aop.config.BindingAdvice - com.example.aop.web.UserController.update() => 필드 : username, 메시지 : 패스워드를 입력하세요
|
||||
@@ -51,8 +51,8 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>io.sentry</groupId>
|
||||
<artifactId>sentry</artifactId>
|
||||
<version>3.2.1</version>
|
||||
<artifactId>sentry-spring-boot-starter</artifactId>
|
||||
<version>4.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.example.aop.config;
|
||||
|
||||
import com.example.aop.domain.CommonDto;
|
||||
import io.sentry.Sentry;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.After;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
@@ -9,7 +11,6 @@ import org.aspectj.lang.annotation.Before;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.FieldError;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
@@ -21,8 +22,11 @@ import java.util.Map;
|
||||
// @Configuration -> @Controller , @Service, @Repository -> @Component
|
||||
@Component
|
||||
@Aspect
|
||||
@Slf4j
|
||||
public class BindingAdvice {
|
||||
|
||||
// private static final Logger log = LoggerFactory.getLogger(BindingAdvice.class);
|
||||
|
||||
@Before("execution(* com.example.aop.web..*Controller.*(..))")
|
||||
public void before() {
|
||||
HttpServletRequest request =
|
||||
@@ -60,7 +64,12 @@ public class BindingAdvice {
|
||||
.filter(v -> v instanceof BindingResult)
|
||||
.filter(v -> ((BindingResult) v).hasErrors())
|
||||
.forEach(v -> ((BindingResult) v).getFieldErrors()
|
||||
.forEach(error -> errorMap.put(error.getField(), error.getDefaultMessage())));
|
||||
.forEach(error -> {
|
||||
errorMap.put(error.getField(), error.getDefaultMessage());
|
||||
String msg = type + "." + method + "() => 필드 : " + error.getField() + ", 메시지 : " + error.getDefaultMessage();
|
||||
log.warn(msg);
|
||||
Sentry.captureMessage(msg);
|
||||
}));
|
||||
|
||||
return errorMap.isEmpty() ? proceedingJoinPoint.proceed() : new CommonDto<>(errorMap, HttpStatus.BAD_REQUEST.value());
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
10
aop/src/main/resources/application.yml
Normal file
10
aop/src/main/resources/application.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
logging:
|
||||
level:
|
||||
root: INFO
|
||||
com.example.aop: WARN
|
||||
|
||||
file:
|
||||
path: logs
|
||||
|
||||
sentry:
|
||||
dsn: https://f9bcef6bf8cc45fdb998f145c1ccb763@o515324.ingest.sentry.io/5619969
|
||||
33
aop/src/main/resources/logback-spring
Normal file
33
aop/src/main/resources/logback-spring
Normal file
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<property name="LOGS_ABSOLUTE_PATH" value="./logs" />
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<layout class="ch.qos.logback.classic.PatternLayout">
|
||||
<Pattern>[%d{yyyy-MM-dd HH:mm:ss}:%-3relative][%thread] %-5level %logger{36} - %msg%n</Pattern>
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${LOGS_ABSOLUTE_PATH}/logback.log</file>
|
||||
<encoder>
|
||||
<pattern>[%d{yyyy-MM-dd HH:mm:ss}:%-3relative][%thread] %-5level %logger{35} - %msg%n</pattern>
|
||||
</encoder>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>${LOGS_ABSOLUTE_PATH}/logback.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
|
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||
<maxFileSize>5MB</maxFileSize>
|
||||
</timeBasedFileNamingAndTriggeringPolicy>
|
||||
<maxHistory>30</maxHistory>
|
||||
</rollingPolicy>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
|
||||
<logger name="com.example.aop.config" level="WARN">
|
||||
<appender-ref ref="FILE" />
|
||||
</logger>
|
||||
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user