You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by GitBox <gi...@apache.org> on 2022/06/17 15:23:54 UTC

[GitHub] [incubator-shenyu] li-keguo commented on pull request #3576: [ISSUE #3523]Add AOP for shenyu-examples-websocket.

li-keguo commented on PR #3576:
URL: https://github.com/apache/incubator-shenyu/pull/3576#issuecomment-1158980315

   hi ~ I have some suggestion:
   The logging code looks similar,
   You can provide a separate module, e.g. xxxx-log-starter.
   add some code.
   
   ```java
   
   public @interface Log {
   }
   @Aspect
   @Component
   public class LogInterceptor {
   
       private static final Logger log = LoggerFactory.getLogger(LogInterceptor.class);
   
       @Pointcut("@annotation(org.apache.shenyu.examples.websocket.aop.Log)")
       public void logPointcut() {
           //just for pointcut
       }
   
       @Around("logPointcut()")
       public Object around(ProceedingJoinPoint point) throws Throwable {
           try {
               log.info("before proceed");
               return point.proceed(point.getArgs());
           } finally {
               log.info("after proceed");
           }
       }
   }
   
   ```
   
   Then import it in the example,You can use the @Log annotation directly, and it can also be used in other places where it is needed, such as admin.
   
   ```xml
           <dependency>
               <groupId>org.apache.shenyu.boot</groupId>
               <artifactId>xxxx-log-starter</artifactId>
           </dependency>
   ```
   
   Of course, the parameters of the @log annotation can be enriched


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org