@aspect
@component
public class logaop {}
@pointcut(value = "@annotation(cn.stylefeng.guns.core.common.annotion.bussinesslog)")
public void cutservice()
@around("cutservice()")
public object recordsyslog(proceedingjoinpoint point) throws throwable catch (exception e)
return result;
}
@bussinesslog(value = "新增角色", key = "name", dict = roledict.class)
public responsedata add(@valid role role, bindingresult result)
role.setid(null);
this.roleservice.insert(role);
return success_tip;
}注意: 在實際記錄日誌時候,需要開啟執行緒記錄,因為記錄操作會非常多防止堵塞主線程
//非同步操作記錄日誌的執行緒池
private scheduledthreadpoolexecutor executor = new scheduledthreadpoolexecutor(10);
@async
public void async(){}
@around("cutservice()")
public object recordsyslog(proceedingjoinpoint point) throws throwable catch (exception e)
return result;
}
private void handle(proceedingjoinpoint point) throws exception
msig = (methodsignature) sig;
object target = point.gettarget();
method currentmethod = target.getclass().getmethod(msig.getname(), msig.getparametertypes());
string methodname = currentmethod.getname();
//攔截的實體類
object target = point.gettarget();
//攔截的方法名稱
string methodname = point.getsignature().getname();
//攔截的方法引數
object args = point.getargs();
//攔截的放引數型別
class parametertypes = ((methodsignature)point.getsignature()).getmethod().getparametertypes();
method m = null;
try
}//獲得parametertype引數型別的方法
m = target.getclass().getmethod(methodname, parametertypes);
//獲取操作名稱
bussinesslog annotation = currentmethod.getannotation(bussinesslog.class);
string bussinessname = annotation.value();
string key = annotation.key();
class dictclass = annotation.dict();
@bussinesslog(value = "新增角色", key = "name", dict = roledict.class)
@permission(const.admin_name)
@responsebody
public responsedata add(@valid role role, bindingresult result)
role.setid(null);
this.roleservice.insert(role);
return success_tip;
}
SpringBoot 日誌 切換日誌框架
在sprinboot切換日誌框架其實是不提倡的,使用預設的slf4j logback就可以了,但非要換也沒辦法是把哈哈 從logback切換到log4j,使用log4j作為實現 1.參照log4j和slf4j的關係圖 3.加入適配log4j的jar包,該包直接依賴了log4j的jar包,所以就不必再...
SpringBoot 日誌框架
1 市面上的日誌框架 jul jcl jboss logging logback log4j log4j2 slf4j.springboot中使用的日誌框架 日誌介面層 slf4j 日誌實現 logback spring使用的日誌框架 jcl commons logging 2 slf4j的使用 開...
日誌框架logback springboot
logback debug utf 8 加入下面這個標籤日誌檔案按這個標籤的路徑儲存 否則將按的路徑儲存 true log debug.log d thread 5level logger msg n utf 8 debug log debug d.log 15debug accept deny 加...