开发打印访问日志
package com.cbcs.agile.common.core.aspect;
import com.cbcs.agile.common.core.util.JsonUtils;
import lombok.AllArgsConstructor;
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 javax.servlet.http.HttpServletRequest;
@Slf4j
@Aspect
@Component
@AllArgsConstructor
public class DevelopLogAspect {
private final HttpServletRequest request;
@Pointcut("execution(public * com.cbcs..*.controller..*.*(..))")
public void developLog() {
}
@Around("developLog()")
public Object developLogAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
long startTime = System.currentTimeMillis();
log.info("========================================== Start ==========================================");
log.info("URL : {}", request.getRequestURL().toString());
log.info("HTTP Method : {}", request.getMethod());
log.info("Class Method : {}.{}", proceedingJoinPoint.getSignature().getDeclaringTypeName(),
proceedingJoinPoint.getSignature().getName());
log.info("IP : {}", request.getRemoteAddr());
log.info("Request Args : {}", JsonUtils.encode(proceedingJoinPoint.getArgs()));
Object result = proceedingJoinPoint.proceed();
log.info("Response Args : {}", JsonUtils.encode(result));
log.info("Time-Consuming : {} ms", System.currentTimeMillis() - startTime);
log.info("=========================================== End ===========================================");
log.info("");
return result;
}
}
复制代码