-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from IT-Cotato/feature/92-implement-manage-log
Feature: 프로필 별 로그 관리 및 로그 출력 설정(#92)
- Loading branch information
Showing
27 changed files
with
724 additions
and
492 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
13 changes: 7 additions & 6 deletions
13
backend/src/main/java/middle_point_search/backend/BackendApplication.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
58 changes: 58 additions & 0 deletions
58
backend/src/main/java/middle_point_search/backend/common/aop/LogAspect.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,58 @@ | ||
package middle_point_search.backend.common.aop; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.aspectj.lang.annotation.Pointcut; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.context.request.RequestContextHolder; | ||
import org.springframework.web.context.request.ServletRequestAttributes; | ||
|
||
@Aspect | ||
@Slf4j | ||
@Component | ||
public class LogAspect { | ||
|
||
@Pointcut("execution(* middle_point_search.backend..*.*(..)) && !execution(* middle_point_search.backend.common..*(..))") | ||
public void all() { | ||
} | ||
|
||
@Pointcut("execution(* middle_point_search.backend..*Controller.*(..))") | ||
public void controller() { | ||
} | ||
|
||
@Around("all()") | ||
public Object logging(ProceedingJoinPoint joinPoint) throws Throwable { | ||
long start = System.currentTimeMillis(); | ||
try { | ||
Object result = joinPoint.proceed(); | ||
return result; | ||
} finally { | ||
long end = System.currentTimeMillis(); | ||
long timeinMs = end - start; | ||
log.info("{} | time = {}ms", joinPoint.getSignature(), timeinMs); | ||
} | ||
} | ||
|
||
@Around("controller()") | ||
public Object loggingBefore(ProceedingJoinPoint joinPoint) throws Throwable { | ||
final HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); | ||
final String ipAddr = request.getRemoteAddr(); | ||
final String method = request.getMethod(); | ||
final String requestURI = request.getRequestURI(); | ||
final Object[] args = joinPoint.getArgs(); | ||
|
||
log.info("[REQUEST] {} {} {} args={}", ipAddr, method, requestURI, args); | ||
try { | ||
Object result = joinPoint.proceed(); | ||
log.info("[RESPONSE] {}", result); | ||
return result; | ||
} catch (Exception e) { | ||
log.error("[RESPONSE] exception message = {} {}", e.getMessage(), e.getStackTrace()[0]); | ||
throw e; | ||
} | ||
} | ||
|
||
} |
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
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
Oops, something went wrong.