-
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.
Merge branch 'develop' of https://github.com/sopt-makers/sopt-crew-ba…
- Loading branch information
Showing
6 changed files
with
112 additions
and
2 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
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
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
71 changes: 71 additions & 0 deletions
71
main/src/main/java/org/sopt/makers/crew/main/common/aop/ExecutionLoggingAop.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,71 @@ | ||
package org.sopt.makers.crew.main.common.aop; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import java.security.Principal; | ||
import java.util.Objects; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.sopt.makers.crew.main.common.util.UserUtil; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.util.StopWatch; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.context.request.RequestContextHolder; | ||
import org.springframework.web.context.request.ServletRequestAttributes; | ||
|
||
@Aspect | ||
@Component | ||
@Log4j2 | ||
public class ExecutionLoggingAop { | ||
|
||
// 모든 패키지 내의 controller package에 존재하는 클래스 | ||
@Around("execution(* org.sopt.makers.crew..*Controller.*(..))") | ||
public Object logExecutionTrace(ProceedingJoinPoint pjp) throws Throwable { | ||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest(); | ||
RequestMethod httpMethod = RequestMethod.valueOf(request.getMethod()); | ||
|
||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | ||
Integer userId = (Integer) authentication.getPrincipal(); | ||
|
||
String className = pjp.getSignature().getDeclaringType().getSimpleName(); | ||
String methodName = pjp.getSignature().getName(); | ||
String task = className + "." + methodName; | ||
|
||
log.info("[Call Method] " + httpMethod.toString() + ": " + task + " | Request userId=" + userId.toString()); | ||
|
||
Object[] paramArgs = pjp.getArgs(); | ||
for (Object object : paramArgs) { | ||
if (Objects.nonNull(object)) { | ||
log.info("[parameter type] {}", object.getClass().getSimpleName()); | ||
log.info("[parameter value] {}", object); | ||
} | ||
} | ||
|
||
// 해당 클래스 처리 전의 시간 | ||
StopWatch sw = new StopWatch(); | ||
sw.start(); | ||
|
||
Object result = null; | ||
|
||
// 해당 클래스의 메소드 실행 | ||
try{ | ||
result = pjp.proceed(); | ||
} | ||
catch (Exception e){ | ||
log.warn("[ERROR] " + task + " 메서드 예외 발생 : " + e.getMessage()); | ||
throw e; | ||
} | ||
|
||
// 해당 클래스 처리 후의 시간 | ||
sw.stop(); | ||
long executionTime = sw.getTotalTimeMillis(); | ||
|
||
log.info("[ExecutionTime] " + task + " --> " + executionTime + " (ms)"); | ||
|
||
return result; | ||
} | ||
|
||
} |
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,8 @@ | ||
<included> | ||
<appender name="CONSOLE" | ||
class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>${LOG_PATTERN}</pattern> | ||
</encoder> | ||
</appender> | ||
</included> |
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,28 @@ | ||
<configuration> | ||
<timestamp key="BY_DATE" datePattern="yyyy-MM-dd"/> | ||
<property name="LOG_PATTERN" | ||
value="[%d{yyyy-MM-dd HH:mm:ss}:%-4relative] %green([%thread]) %highlight(%-5level) %boldWhite([%C.%M:%yellow(%L)]) - %msg%n"/> | ||
|
||
<springProfile name="local"> | ||
<include resource="console-appender.xml"/> | ||
|
||
<root level="INFO"> | ||
<appender-ref ref="CONSOLE"/> | ||
</root> | ||
</springProfile> | ||
|
||
<springProfile name="dev"> | ||
<include resource="console-appender.xml"/> | ||
|
||
<root level="INFO"> | ||
<appender-ref ref="CONSOLE"/> | ||
</root> | ||
</springProfile> | ||
|
||
<springProfile name="prod"> | ||
<include resource="console-appender.xml"/> | ||
<root level="INFO"> | ||
<appender-ref ref="CONSOLE"/> | ||
</root> | ||
</springProfile> | ||
</configuration> |