누구나 메소드 엔트리 (파라미터 값 포함)를 로그하고 Spring AOP 및 log4j를 트레이스 레벨에서 종료하는 방법에 대한 아이디어가 있습니다. 여러 패키지의 클래스를 기록 할 수 있어야합니다.Spring AOP로 메소드 엔트리 로그하기
1
A
답변
2
Spring 프레임 워크의 PerformanceMonitorInterceptor를 사용하여 메소드 항목을 기록 할 수 있습니다. Here은 DZone의 샘플 사용법입니다. 모든 방법은 com.blablabla.server 패키지 아래의 모든 하위 패키지를 요구 측면 로그 주변이 예에서
@Component
@Aspect
@Order(value=2)
public class LoggingAspect {
@Around("execution(* com.blablabla.server..*.*(..))")
public Object logMethod(ProceedingJoinPoint joinPoint) throws Throwable{
final Logger logger = LoggerFactory.getLogger(joinPoint.getTarget().getClass().getName());
Object retVal = null;
try {
StringBuffer startMessageStringBuffer = new StringBuffer();
startMessageStringBuffer.append("Start method ");
startMessageStringBuffer.append(joinPoint.getSignature().getName());
startMessageStringBuffer.append("(");
Object[] args = joinPoint.getArgs();
for (int i = 0; i < args.length; i++) {
startMessageStringBuffer.append(args[i]).append(",");
}
if (args.length > 0) {
startMessageStringBuffer.deleteCharAt(startMessageStringBuffer.length() - 1);
}
startMessageStringBuffer.append(")");
logger.trace(startMessageStringBuffer.toString());
StopWatch stopWatch = new StopWatch();
stopWatch.start();
retVal = joinPoint.proceed();
stopWatch.stop();
StringBuffer endMessageStringBuffer = new StringBuffer();
endMessageStringBuffer.append("Finish method ");
endMessageStringBuffer.append(joinPoint.getSignature().getName());
endMessageStringBuffer.append("(..); execution time: ");
endMessageStringBuffer.append(stopWatch.getTotalTimeMillis());
endMessageStringBuffer.append(" ms;");
logger.trace(endMessageStringBuffer.toString());
} catch (Throwable ex) {
StringBuffer errorMessageStringBuffer = new StringBuffer();
// Create error message
logger.error(errorMessageStringBuffer.toString(), e)
throw ex;
}
return retVal;
}
}
:
4
당신은 @Around (..) 등의 목적으로 측면을 사용할 수 있습니다. 또한 모든 메소드 입력 매개 변수를 기록합니다.
관련 문제
- 1. Spring AOP로 원 자성이 보장됩니까?
- 2. Spring AOP로 @ Before/@ Post 구현하기
- 3. Spring AOP로 특정 주석을 가로 채기
- 4. Spring 컨트롤러의 각 메소드 이전에 AOP로 일부 코드를 실행하고 Method 객체가있는 방법
- 5. AOP로 인한 스프링 보안 오류
- 6. Spring 초기화 메소드 매개 변수
- 7. Spring MVC @Controller 메소드 서명
- 8. Spring LDAP ODM - 엔트리 클래스를 final로 선언해야합니다. 경고
- 9. Spring.net, AOP로 인해 속성을 설정할 수 없습니다.
- 10. Go Language를 사용하여 로그하기 간단한 HTTP 서버
- 11. Spring MVC에서 메소드 인수로서의 세션 속성
- 12. Spring aop을 통한 동시 메소드 호출 제한
- 13. Spring MVC에서의 메소드 처리 - 동일한 URL 경로
- 14. 유닛 테스트 Spring @Around AOP 메소드
- 15. Spring Annotated 컨트롤러로의 이전과 전통적인 onSubmit 메소드
- 16. Spring MVC에서 PUT 및 DELETE 메소드 사용하기
- 17. Spring Lookup 메소드 삽입이 작동하지 않음
- 18. XML 응답을위한 Spring RestTemplate POST 메소드?
- 19. Spring 3 MVC 컨트롤러 메소드 만들기 Transaction
- 20. Spring Controller (주석 버전)의 Init 메소드
- 21. Spring 하이버 네이트의 @Transient 메소드 호출
- 22. 주석 기반 AOP로 컨트롤러 응답 수정하기?
- 23. GWT를 사용하여 엔트리 포인트에서 다른 엔트리 포인트로 패스하는 방법은 무엇입니까?
- 24. 메서드의 두 엔트리 포인트를 구별하십시오
- 25. py2exe에와 PyGTK 엔트리 포인트
- 26. 예쁜 HABTM리스트 엔트리
- 27. tkinter 엔트리 위젯과 변수
- 28. 설정 값은 엔트리
- 29. mysql 질의 - 엔트리 제외
- 30. 엔트리 삭제하기 안드로이드에서 SharedPreferences