2011-09-04 97 views

回答

22

是的,有!

<bean id="customizableTraceInterceptor" class="org.springframework.aop.interceptor.CustomizableTraceInterceptor"> 
    <property name="enterMessage" value="Entering $[methodName]($[arguments])"/> 
    <property name="exitMessage" value="Leaving $[methodName](): $[returnValue]"/> 
</bean> 
<aop:config> 
    <aop:advisor advice-ref="customizableTraceInterceptor" pointcut="execution(public * BankAccountServlet.*(..))"/> 
</aop:config> 

時退房CustomizableTraceInterceptor API,你可以定義不同的幾個佔位符進入/退出/異常消息:

  • $[methodName] - 替換的方法被調用
  • $[targetClassName]名稱 - 替換爲調用目標類的名稱
  • $[targetClassShortName] - 替換爲這是調用
  • $[returnValue]的目標之類的短名稱 - 替換爲調用
  • $[argumentTypes]返回的值 - 替換爲一個逗號分隔的方法參數的短類名列表
  • $[arguments] - 替換爲逗號分隔的方法參數
  • $[exception] String表示的列表 - 替換爲調用
  • $[invocationTime]期間提出的任何的Throwable的String表示 - 隨着時間的替代,以毫秒爲單位,所採取的方法在職業
+0

有趣的是,明天將嘗試它,你能發佈鏈接我可以在哪裏讀到它?謝謝 –

+0

是的,謝謝,我剛剛閱讀它:) –

+0

@Tomasz - 我在OSGI包中的Eclipse Virgo服務器上試過這個。它沒有將日誌打印到日誌文件中。我懷疑它是因爲編織問題。但我完全不知道。你能幫我麼?提前致謝。 – Sam

0

這裏是指那些通過AOP日誌框架的列表:

http://aspect4log.sf.net - 確實非常好看通過SLF4J和@Log註解記錄。 可以通過SpringAOP和AspectJ工作。使用AspectJ,它甚至可以用於私有方法和構造函數,並且不需要類就可以成爲Spring Bean。 非常容易使用,我能夠在5分鐘內使其與我的項目一起運行。

http://loggifier.unkrig.de - 通過java.util.logging進行日誌記錄,有點過於複雜,並沒有那麼好的文檔,但聲稱它可以測試已經編譯過的jar/war/ear文件!

AbstractTraceInterceptor(來自SpringAOP)及其子類SimpleTraceInterceptor和CustomizableTraceInterceptor。日誌記錄配置與類別分開進行。通過公共日誌記錄日誌。由於它是爲SpringAOP設計的,因此您必須使用Spring Beans(並且只能使用Spring Bean公共方法)。