注意:Action如果實現(xiàn)了Action接口,或者繼承了ActionSupport類,則要在aop:config標簽添加 proxy-target-class="true",否者會拋異常。
新建文件:DebugLogger.java:
import org.apache.log4j.Logger;
import org.aspectj.lang.JoinPoint;
public class DebugLogger{
Logger logger = Logger.getLogger(DebugLogger.class);
StringBuffer buffer = new StringBuffer();
public void log(JoinPoint joinPoint) {
Object[] args = joinPoint.getArgs();
buffer.delete(0, buffer.length()).append("enter function: ").append(joinPoint.getSignature()).append(", parameters: ");
if (args != null) {
for (Object obj : args) {
buffer.append(obj);
}
}
if (logger.isDebugEnabled())
{
logger.debug(buffer.toString());
}
}
public void logWithReturn(JoinPoint joinPoint, Object returnObj) {
buffer.delete(0, buffer.length()).append("exit function:").append(joinPoint.getSignature()).append(", return value:").append(returnObj);
if (logger.isDebugEnabled())
{
logger.debug(buffer.toString());
}
}
}
-----------------------------------------------------------默默無聞的分割線-----------------------------------------------------------
更改applicationContext.xml文件:
<bean id="debugLogger" class="com.shenzhen.management.util.log.DebugLogger"></bean>
<aop:config proxy-target-class="true">
<aop:pointcut id="logPointcut" expression="execution(* com.shenzhen.management.action.*.*(..))
or execution(* com.shenzhen.management.service.*.*(..))
or execution(* com.shenzhen.management.dao.*.*(..))"/>
<aop:aspect id="logAspect" ref="debugLogger">
<aop:before method="log" pointcut-ref="logPointcut"/>
<aop:after-returning method="logWithReturn" returning="returnObj" pointcut-ref="logPointcut"/>
</aop:aspect>
</aop:config>
創(chuàng)新互聯(lián)www.cdcxhl.cn,專業(yè)提供香港、美國云服務器,動態(tài)BGP最優(yōu)骨干路由自動選擇,持續(xù)穩(wěn)定高效的網(wǎng)絡助力業(yè)務部署。公司持有工信部辦法的idc、isp許可證, 機房獨有T級流量清洗系統(tǒng)配攻擊溯源,準確進行流量調(diào)度,確保服務器高可用性。佳節(jié)活動現(xiàn)已開啟,新人活動云服務器買多久送多久。
當前標題:切入Debug日志-創(chuàng)新互聯(lián)
轉載來源:http://chinadenli.net/article48/degjep.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、關鍵詞優(yōu)化、網(wǎng)站維護、全網(wǎng)營銷推廣、建站公司、營銷型網(wǎng)站建設
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容