Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/tracing method #8

Merged
merged 2 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.plus.taxiapp.shared.advice.exception
package com.plus.taxiapp.shared.aop.advice

import com.plus.taxiapp.shared.exception.ErrorResponse
import lombok.extern.slf4j.Slf4j
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.plus.taxiapp.shared.aop.aspect

import lombok.extern.slf4j.Slf4j
import org.aspectj.lang.JoinPoint
import org.aspectj.lang.annotation.AfterReturning
import org.aspectj.lang.annotation.Aspect
import org.aspectj.lang.annotation.Before
import org.hibernate.query.sqm.tree.SqmNode.log
import org.springframework.stereotype.Component

@Aspect
@Component
@Slf4j
class LoggingAspect {
@Before("execution(* com.plus.taxiapp..*.*(..))")
fun beforeMethodCall(joinPoint: JoinPoint) {
val methodName = joinPoint.signature.name
val args = joinPoint.args.joinToString(", ") // 모든 인자를 문자열로 변환

val threadId = Thread.currentThread().id
val timestamp = System.currentTimeMillis()
val instanceId = "[미정]"

val traceId = "$instanceId-$timestamp-$threadId"
log.info("[$traceId] [${System.currentTimeMillis()}] [$methodName] called with args: $args")
}

@AfterReturning(pointcut = "execution(* com.plus.taxiapp..*.*(..))", returning = "result")
fun afterMethodCall(joinPoint: JoinPoint, result: Any?) {
val methodName = joinPoint.signature.name
val args = joinPoint.args.joinToString(", ")

val threadId = Thread.currentThread().id
val timestamp = System.currentTimeMillis()
val instanceId = "[미정]"

val traceId = "$instanceId-$timestamp-$threadId"
log.info("[$traceId] [${System.currentTimeMillis()}] [$methodName] called with args: $args, returned: $result")
}

}
Loading