일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
- maVen
- Quartz
- xargs
- IntelliJ
- GIT
- 줄바꿈 문자
- JavaScript
- import
- 단축키
- vscode
- ssh
- VirtualBox
- port
- context
- grep
- bash
- tomcat
- Windows
- 네트워크
- profile
- lsof
- plugin
- resource
- Source
- Eclipse
- Mac
- Windows 10
- find
- netsh
- web.xml
- Today
- Total
develog
Spring AOP LoggingAdvice 본문
import java.util.List;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class LoggingAdvice {
private Log logger = LogFactory.getLog(getClass());
public void before(JoinPoint joinPoint) {
if (!logger.isDebugEnabled()) return;
StringBuffer sb = new StringBuffer();
sb.append(getMethodNm(joinPoint));
sb.append(" (before)");
sb.append(getArgs(joinPoint));
logger.debug(sb.toString());
}
public void afterReturning(JoinPoint joinPoint, Object retVal) {
if (!logger.isDebugEnabled()) return;
StringBuffer sb = new StringBuffer();
sb.append(getMethodNm(joinPoint));
sb.append(" (afterReturning)");
if (retVal instanceof List) {
List list = (List) retVal;
if (list == null) {
sb.append("\n" + " " + "LIST, " + "null");
} else {
sb.append("\n" + " " + "LIST, " + list.size() + " 건");
}
} else {
sb.append("\n" + " " + retVal);
}
logger.debug(sb.toString());
}
private String getMethodNm(JoinPoint joinPoint) {
Signature signature = joinPoint.getSignature();
StringBuffer sb = new StringBuffer();
sb.append(signature.getDeclaringTypeName());
sb.append(".");
sb.append(signature.getName());
return sb.toString();
}
private String getArgs(JoinPoint joinPoint) {
StringBuffer sb = new StringBuffer();
Object[] args = joinPoint.getArgs();
for (int i = 0; i < args.length; i++) {
Object object = args[i];
if (object instanceof List) {
sb.append("\n" + " " + i + ". ");
List list = (List) object;
if (list == null) continue;
for (int j = 0; j < list.size(); j++) {
sb.append("\n" + " " + j + ". " + list.get(j));
}
} else {
sb.append("\n" + " " + i + ". " + object);
}
}
return sb.toString();
}
}
'Dev > Spring' 카테고리의 다른 글
Spring AOP Pointcut expression (0) | 2013.12.11 |
---|---|
Spring AOP 설정 (0) | 2013.12.11 |
REQUIRED, REQUIRES_NEW (0) | 2013.07.18 |
spring jar download (0) | 2013.07.09 |
Spring AOP Aspect 설정 (0) | 2013.04.22 |