Actionの実行時間をログ出力 ‐TimerInterceptor
xwork2のTimerInterceptorは、以下のようにActionの実行時間をログに出力できます。
2007-05-18 14:25:51,711 INFO [http-8080-Processor23] [com.opensymphony.xwork2.interceptor.TimerInterceptor] - Executed action [/catalog/list!list] took 1500 ms.
struts.xmlのdefalutStackには定義されていないので、interceptor-stackに追加します。
LoggingInterceptorと違ってログレベルやログカテゴリの設定ができます。結構便利。
<interceptor name="action-timer" class="com.opensymphony.xwork2.interceptor.TimerInterceptor"> <param name="logLevel">info</param> <!--<param name="logCategory"></param> --> </interceptor> <interceptor-stack name="myapp-eshopStack"> <interceptor-ref name="logger" /> <interceptor-ref name="action-timer" /> <interceptor-ref name="defaultStack" /> ... </interceptor-stack>
log4j.xmlの設定も必要です。
カテゴリを変更した場合は、logCategoryで設定した値を指定します。
<logger name="com.opensymphony.xwork2.interceptor.TimerInterceptor" additivity="false"> <level value="INFO" /> <appender-ref ref="STDOUT" /> </logger>