基于Aspect的日志记录参数

阅读更多
import java.util.Arrays;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.springframework.stereotype.Service;

import com.auto.RestLogger;

@Service
@Aspect
public class LogParamAspect
{
    public static Logger logger = RestLogger.getLogger();

    @Before("execution(public * com.auto.common.rest..*.*Service.*(..))")
    public void paramCheck(JoinPoint joinPoint)
    {
        logger.trace("Request Method:[{}], Params: {}", joinPoint.getSignature().getDeclaringTypeName() + "."
                + joinPoint.getSignature().getName(), Arrays.toString(joinPoint.getArgs()));
    }
}

你可能感兴趣的:(java)