You should use another class Matcher. Currently you configured your binder
to adapt all injected classes, no matter where they're located.

To do what you want, you should change your binding to the following:

    bindInterceptor(Matchers.inSubpackage("org.cal.bento"), Matchers.any(),
new GuiceLoggingInterceptor());

Le lun. 25 juil. 2016 à 13:10, Ankur Mahajan <[email protected]>
a écrit :

> I am trying to implement AOP based logging in Google - Guice. I have used "
> *MethodInterceptor*" for this but it doesn't work. I have used same in
> Spring by defining point-cuts. Everything is working fine there.
>
> *Spring Code for AOP based logging -*
>
> @Aspect
> public class LoggingAspect {
>
>  private static Logger logger = LoggerFactory.getLogger(LoggingAspect.
> class);
>
>    @Around("requiredLog()")
>    public Object bentoBoxAround(ProceedingJoinPoint proceedingJoinPoint) {
>
>       Object returnValue = null;
>       try {
>
>           logger.info("Entered into the method -> " + proceedingJoinPoint.
> getSignature().toShortString()
>                   + " and input arguments are -> " + Arrays.asList(
> proceedingJoinPoint.getArgs()));
>           returnValue = proceedingJoinPoint.proceed();
>           logger.info("Method Execution over !! " + proceedingJoinPoint.
> getSignature().toShortString());
>       } catch (Throwable e) {
>           logger.error("Method has an exception " + e.getMessage());
>       }
>       return returnValue;
>    }
>
>    @Pointcut("within(org.cal.bento..*)")
>    public void allRequiredPakageLog() {
>    }
>
>  }
>
>
> From above code we can log all the class and method executions inside the "
> org.cal.bento.*" package.
>
> *Guice code for AOP based logging -*
>
> public class GuiceLoggingInterceptor implements MethodInterceptor {
>
>  private static Logger logger = LoggerFactory
>  .getLogger(GuiceLoggingInterceptor.class);
>
>   @Override
>   public Object invoke(MethodInvocation invocation) throws Throwable {
>     Object returnValue = null;
>     try {
>         logger.info("GUICE - Entered into the method -> " + invocation.
> getMethod().getName()
>                     + " and input arguments are -> " + Arrays.asList(
> invocation.getArguments()));
>         returnValue = invocation.proceed();
>         logger.info("Method Execution over !! " + invocation.getMethod().
> getName());
>     } catch (Throwable e) {
>         logger.error("GUICE - Method has an exception " + e.getMessage());
>     }
>     return returnValue;
>   }
> }
>
> *Binding Class -*
>
> public class GuiceAopModule extends AbstractModule {
>
>   @Override
>   protected void configure() {
>       bindInterceptor(Matchers.any(), Matchers.any(), new
> GuiceLoggingInterceptor());
>   }
> }
>
> Can we do similar in Guice for logging (write only one Aspect based class
> for whole logging system). I don't want to modify every class.
> *Refered Tutorial* -
> https://schakrap.wordpress.com/2009/07/30/method-entry-exit-logging-in-guice-with-aop/
> Any help would be highly appreciated.
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-guice" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/google-guice.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-guice/23ee65b0-983b-47db-81f1-06d9ed618b69%40googlegroups.com
> <https://groups.google.com/d/msgid/google-guice/23ee65b0-983b-47db-81f1-06d9ed618b69%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/CAORw%3DcO4Esa3jTSq80uEj%3DpEHK2CfKqi8o-LsYFue%2B6Lf%3D7rMw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to