The first one you point to is a “Built-in Binding”.  However, I do not see
this in the guice-3.0.jar.  Also, how do I use it?

 

The second link on Custom Injections scans for a Logger in each class, so
this does not seem to be using AOP.

 

Here is the class I came up with, below.  My problem is that I don’t see how
to install the pointcut to intercept a specific method in a class.  I can
bind it to all methods, but not one method.  How can I do that?

 

public class WhisperModule extends AbstractMurmurModule {

 

       @Override

       protected void configure() {

              …

 

bindInterceptor(Matchers.subclassesOf(WhisperTerminal.class),
Matchers.any(), new LoggingInterceptor());

       }

}

 

public class LoggingInterceptor implements MethodInterceptor {

    private Logger logger;

 

    public LoggingInterceptor() {

       PropertyConfigurator.configure("log4j.properties");

       logger = Logger.getLogger(LoggingInterceptor.class);

    }

 

    public Object invoke(MethodInvocation methodInvocation) throws Throwable
{

       String header = methodInvocation.getThis().getClass()

                     + ":" + methodInvocation.getMethod().getName();

        logger.info(header + " invocation");

        Object result = null;

        try {

            result = methodInvocation.proceed();

            logger.info(header + " return: " + result);

            return result;

        } catch (Exception ex) {

            logger.error(header, ex);

              throw ex;

        }

    }

}

 

 

Thanks,

Rob

 

From: [email protected] [mailto:[email protected]]
On Behalf Of Cédric Beust ?
Sent: Tuesday, October 09, 2012 10:56 PM
To: [email protected]
Subject: Re: Aspect logging in Guice?

 

Something like that
<http://code.google.com/p/google-guice/wiki/BuiltInBindings> ?

 

Or you could inject your own loggers with type listeners
<http://code.google.com/p/google-guice/wiki/CustomInjections> .


-- 

Cédric





On Tue, Oct 9, 2012 at 5:31 PM, Rob Withers <[email protected]> wrote:

Before I run off and implement a LoggingInterceptor, is there an AOP logging
facility in core guice or an extension I could use?

 

Thanks,
Rob

-- 
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-guice/-/rphjmZue5wQJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected]
<mailto:google-guice%[email protected]> .
For more options, visit this group at
http://groups.google.com/group/google-guice?hl=en.

 

-- 
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en.

Reply via email to