首页>代码>jHipster3.4创建Java Web应用项目最简单的入门基本教程>/kenlen1/kenlen/src/main/java/com/emodak/kenlen/aop/logging/LoggingAspect.java
package com.emodak.kenlen.aop.logging;
import com.emodak.kenlen.config.Constants;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
import javax.inject.Inject;
import java.util.Arrays;
/**
* Aspect for logging execution of service and repository Spring components.
*/
@Aspect
public class LoggingAspect {
private final Logger log = LoggerFactory.getLogger(this.getClass());
@Inject
private Environment env;
@Pointcut("within(com.emodak.kenlen.repository..*) || within(com.emodak.kenlen.service..*) || within(com.emodak.kenlen.web.rest..*)")
public void loggingPointcut() {
}
@AfterThrowing(pointcut = "loggingPointcut()", throwing = "e")
public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {
if (env.acceptsProfiles(Constants.SPRING_PROFILE_DEVELOPMENT)) {
log.error("Exception in {}.{}() with cause = {} and exception {}", joinPoint.getSignature().getDeclaringTypeName(),
joinPoint.getSignature().getName(), e.getCause(), e);
} else {
log.error("Exception in {}.{}() with cause = {}", joinPoint.getSignature().getDeclaringTypeName(),
joinPoint.getSignature().getName(), e.getCause());
}
}
@Around("loggingPointcut()")
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
if (log.isDebugEnabled()) {
log.debug("Enter: {}.{}() with argument[s] = {}", joinPoint.getSignature().getDeclaringTypeName(),
joinPoint.getSignature().getName(), Arrays.toString(joinPoint.getArgs()));
}
try {
Object result = joinPoint.proceed();
if (log.isDebugEnabled()) {
log.debug("Exit: {}.{}() with result = {}", joinPoint.getSignature().getDeclaringTypeName(),
joinPoint.getSignature().getName(), result);
}
return result;
} catch (IllegalArgumentException e) {
log.error("Illegal argument: {} in {}.{}()", Arrays.toString(joinPoint.getArgs()),
joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName());
throw e;
}
}
}
最近下载更多
linom199144 LV2
2021年7月5日
jupiterup LV3
2017年5月15日
FunnyKing LV19
2017年4月12日
china_0221 LV41
2017年3月19日
china_0221 LV41
2017年3月19日
ddman9009 LV25
2016年7月13日
wangshanhe LV2
2016年6月15日
最代码官方 LV168
2016年6月12日
最近浏览更多
15719908287 LV10
2024年6月19日
不嘻嘻 LV8
2023年3月31日
why2015 LV21
2022年12月9日
敞开裤裆任雷劈 LV2
2022年1月28日
。
2021年12月3日
暂无贡献等级
Trickster LV9
2021年10月19日
linom199144 LV2
2021年7月5日
xiaobaixiaobai
2021年2月22日
暂无贡献等级
骑着鱼儿过海的猫 LV1
2020年11月25日
Coincidance LV8
2020年11月23日

