Here is my code:
` ` ` Java
@ Aspect
@ Component
@ EnableAspectJAutoProxy
Public class AdviceApi {
The @autowired
Private LogAnalyseService LogAnalyseService;
@ Bean
Public LogChannelCall getBean () {
Return new LogChannelCall ();
}
Private ThreadLocal
The @pointcut (" execution (* com API. Controller. *. * (.. )))
Public void pointcut () {
}
@ Before (pointcut "()")
Public void before () {
It request=((ServletRequestAttributes) RequestContextHolder getRequestAttributes ())
GetRequest ();
String userId=request. The getParameter (" userId ");
String remoteAddr=request. GetRemoteAddr ();
LogChannelCall. SetUserId (userId);
LogChannelCall. SetIp (remoteAddr);
StartTime. Set (System. CurrentTimeMillis ());
}
@ After (pointcut "()")
Public void after () {
HttpServletResponse response=((ServletRequestAttributes) RequestContextHolder getRequestAttributes ()). The method getResponse ();
Boolean successful=response. GetStatus ()==200;
LogChannelCall. SetSuccessful (successful);
}
@ AfterReturning (pointcut "()")
Public void afterReturning () {
LogChannelCall. SetSuccessful (true);
LogChannelCall. SetResponseTime (System. CurrentTimeMillis () - startTime. The get ());
LogAnalyseService. InsertV3Log (logChannelCall);
}
@ AfterThrowing (throwing="ex", pointcut="pointcut () & amp; & ! PointcutPlayAddress () & amp; & ! PointcutInnerPlayAddress () & amp; & ! PointcutProAddress () ")
Public void afterThrowing Exception (ex) {
LogChannelCall. SetSuccessful (false);
LogChannelCall. SetReason (ex. GetMessage ());
LogChannelCall. SetResponseTime (System. CurrentTimeMillis () - startTime. The get ());
LogAnalyseService. InsertV3Log (logChannelCall);
}
}
` ` `
In A large quantity of requests, A log parameters will place B log parameters recorded, A few days ago happened such A thing, A request is executing, B request to the abnormal, B request error log is A record, how do I solve?