0
我使用Spring-AOP來建議一個Spring管理bean,它擴展了實現3個接口的抽象類。在繼承層次結構中還有其他由spring管理的bean。Spring-AOP和SLF4J
我試圖採取最少侵入性的方法,使用彈簧LTW:
<context:component-scan base-package="com.foo.aop"/>
<!-- ... -->
<aop:aspectj-autoproxy proxy-target-class="true"/>
<context:load-time-weaver/>
使用廚房水槽的方法,試圖讓登錄的情況發生:
@Aspect
@Component
public class ForStackOverflow {
private final Log commons = LogFactory.getLog(ForStackOverflow.class);
private final org.apache.log4j.Logger log4j = org.apache.log4j.Logger.getLogger(ForStackOverflow.class);
private final Logger jul = Logger.getLogger(ForStackOverflow.class.getSimpleName());
private final org.slf4j.Logger slf4j = org.slf4j.LoggerFactory.getLogger(ForStackOverflow.class);
@Pointcut(value="within(com.foo.aop.AbstractClass+) " +
"&& execution(* advisedMethod(com.foo.SomeType)) " +
"&& args(someType)")
private void adviseMe(SomeType someType){}
@After(value="adviseMe(com.foo.SomeType) && args(someType)", argNames = "someType")
public void itWorked(SomeType someType) {
String msg = "DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG";
logIt(msg);
IsNotNull(someType, "someType");
String message = "SomeType [ " + someType + "] loaded.";
status(message);
logIt(msg);
}
void status(String message) {
logIt(message);
}
private void logIt(String msg){
System.out.println("STDOUT: " + msg);
System.err.println("STDERR: " + msg);
commons.warn("COMMONS: " + msg);
log4j.warn("LOG4J: " + msg);
jul.warning("JUL: " + msg);
slf4j.warn("SLF4J: " + msg);
}
}
我有證據表明我的方法正在被建議,因爲我可以從那裏拋出並看到堆棧軌跡彈出到適當的位置。
但日誌記錄是難以捉摸的。
(我log4j的銜接和共享記錄到SLF4J。應用程序需要Java util的記錄作爲其底層的實現。)
哪裏是questio在你的問題中標記? – kan 2012-02-13 16:16:55