Last active
January 28, 2020 14:32
-
-
Save Ananto30/4841acf3010d3c7e237708fb9062ba55 to your computer and use it in GitHub Desktop.
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
@Aspect | |
@Slf4j | |
public class LoggerAspect { | |
@Around("@annotation(Loggable)") | |
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable { | |
long start = System.currentTimeMillis(); | |
var result = joinPoint.proceed(); | |
if (result instanceof Mono) { | |
var monoResult = (Mono) result; | |
AtomicReference<String> traceId = new AtomicReference<>(""); | |
return monoResult | |
.doOnSuccess(o -> { | |
var response = ""; | |
if (Objects.nonNull(o)) { | |
response = o.toString(); | |
} | |
log.info("Enter: {}.{}() with argument[s] = {}", | |
joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName(), | |
joinPoint.getArgs()); | |
log.info("Exit: {}.{}() had arguments = {}, with result = {}, Execution time = {} ms", | |
joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName(), | |
joinPoint.getArgs()[0], | |
response, (System.currentTimeMillis() - start)); | |
}); | |
} | |
} | |
} |
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
import java.lang.annotation.ElementType; | |
import java.lang.annotation.Retention; | |
import java.lang.annotation.RetentionPolicy; | |
import java.lang.annotation.Target; | |
/** | |
* @author Azizul Haque Ananto | |
*/ | |
@Retention(RetentionPolicy.RUNTIME) | |
@Target(ElementType.METHOD) | |
public @interface Loggable { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment