0
로거 인스턴스를 스프링과 함께 추가 할 수 있습니까? 그리고 각 사용자 정의 코드에서 각 메소드 호출을 추적하는 방법이 있습니까?로거 추가 스프링
나는 보통 이렇게 :
package my.java.code;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class A {
// How to add this line with Spring ?
private static final Logger logger = LoggerFactory.getLogger(A.class);
public void A() {
// How to add this line with Spring ?
logger.trace("");
// Do something...
}
public void A(Object o) {
// How to add this line with Spring ?
logger.trace("{}", o);
// Do something...
}
public void method1() {
// How to add this line with Spring ?
logger.trace("");
// Do something...
}
public void method2(Object o) {
// How to add this line with Spring ?
logger.trace("{}", o);
// Do something...
}
}
봄과 함께이 문제를 단순화 할 수있는 방법이 있나요?
목표는 다음과 같습니다
- 피하기 repeatitive 코드
나는이 질문을 이해하지 못한다. 네가 가진 것에 뭐가 문제 야? –
중복 된 코드를 제거 하시겠습니까? – geoand
Spring AOP와 ['CustomizableTraceInterceptor'] (http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/aop/interceptor/CustomizableTraceInterceptor.html)를 사용하십시오. http://stackoverflow.com/questions/13182205/java-spring-aop-using-customizabletraceinterceptor-with-javaconfig-enableaspec을 참조하십시오. –