@@ -0,0 +1,2915 @@
+package org.example.seed.logger;%0A%0Aimport com.fasterxml.jackson.core.JsonProcessingException;%0Aimport com.fasterxml.jackson.databind.ObjectMapper;%0Aimport com.fasterxml.jackson.databind.SerializationFeature;%0Aimport org.aspectj.lang.JoinPoint;%0Aimport org.aspectj.lang.ProceedingJoinPoint;%0Aimport org.aspectj.lang.annotation.*;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0Aimport org.springframework.stereotype.Component;%0A%0Aimport java.util.Arrays;%0Aimport java.util.concurrent.Callable;%0A%0A/**%0A * Created by Ricardo Pina Arellano on 21/01/2017.%0A */%0A@Aspect%0A@Component%0Apublic class RESTAspectLogger %7B%0A%0A    private final Logger log = LoggerFactory.getLogger(this.getClass());%0A    private final ObjectMapper objectMapper = new ObjectMapper();%0A%0A    public RESTAspectLogger() %7B%0A        this.objectMapper.enable(SerializationFeature.INDENT_OUTPUT);%0A    %7D%0A%0A    @Pointcut(%22within(org.example.seed.rest..*)%22)%0A    public void rest() %7B%0A    %7D%0A%0A    @Pointcut(%22execution(public * *(..))%22)%0A    protected void allMethod() %7B%0A    %7D%0A%0A    @Before(%22rest() && allMethod()%22)%0A    public void logBefore(JoinPoint joinPoint) throws JsonProcessingException %7B%0A%0A        log.warn(%22Entering in Method :  %22 + joinPoint.getSignature().getName());%0A        log.warn(%22Class Name :  %22 + joinPoint.getSignature().getDeclaringTypeName());%0A        log.warn(%22Arguments :  %22 + this.objectMapper.writeValueAsString(joinPoint.getArgs()));%0A    %7D%0A%0A    @AfterReturning(pointcut = %22rest() && allMethod()%22, returning = %22callable%22)%0A    public void logAfter(JoinPoint joinPoint, Object callable) throws Exception %7B%0A%0A        final Callable%3CObject%3E response = (Callable%3CObject%3E) callable;%0A%0A        log.warn(%22Method Return value : %22 + this.objectMapper.writeValueAsString(response.call()));%0A    %7D%0A%0A    @AfterThrowing(pointcut = %22rest() && allMethod()%22, throwing = %22exception%22)%0A    public void logAfterThrowing(JoinPoint joinPoint, Throwable exception) %7B%0A%0A        log.error(%22An exception has been thrown in %22 + joinPoint.getSignature().getName() + %22 ()%22);%0A        log.error(%22Cause : %22 + exception.getCause());%0A    %7D%0A%0A    @Around(%22rest() && allMethod()%22)%0A    public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable %7B%0A%0A        final long start = System.currentTimeMillis();%0A%0A        try %7B%0A            final String className = joinPoint.getSignature().getDeclaringTypeName();%0A            final String methodName = joinPoint.getSignature().getName();%0A            final Object result = joinPoint.proceed();%0A            final long elapsedTime = System.currentTimeMillis() - start;%0A%0A            log.warn(%22Method %22 + className + %22.%22 + methodName + %22 ()%22 + %22 execution time : %22 + elapsedTime + %22 ms%22);%0A%0A            return result;%0A        %7D catch (final IllegalArgumentException e) %7B%0A            log.error(%22Illegal argument %22 + Arrays.toString(joinPoint.getArgs()) + %22 in %22 + joinPoint.getSignature().getName() + %22()%22);%0A%0A            throw e;%0A        %7D%0A    %7D%0A%7D%0A

add RESTAspectLogger pattern