[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Question about logging:

You would have to write a special aspect that uses the "get()" or
"set()" on an instance field, then write advice that looks at the
value and logs appropriately. However, you can only do this on
instance fields, not locally declared variables.  An alternative is to
define special methods that are called when i is set and you write an
aspect that advices those method calls.Since you can't advice blocks
within a method, e.g., a conditional statement, this is the only way
to advice at those (unsupported) join points. I would consider making
those special methods protected or private (then declare the aspect
'privileged' so it can see them...) so they don't clutter the public
interface.

My $0.02,
dean

On 10/21/05, Pillai, Ranjith <rpillai@xxxxxxxx> wrote:
>
>
>
> Hello Gurus,
>
> I would like to use AOP for logging. All documents talk about logging
> "entering" a method and "exiting": however I didn't see any documents which
> explain the true logging like logging "change in values inside a method" or
> before "executing a statement inside a method" etc. If somebody explain me
> how to do that or direct me to some web documents that would be very
> helpful.
>
>
>
> To illustrate my requirement here is a simple method, what I would like to
> accomplish is remove this cross cutting concern (log statement) and write an
> aspect to achieve the same.
>
>
>
> public  void increment(){
>
>             int i=0;
>
>             log.info(" About to increase the value of i");
>
>             i=i+1;
>
>             if(i==1){
>
>                         log.info(" Value of i is 1 ")
>
>             }
>
> }
>
>
>
> Any help will be deeply appreciated,
>
> Thanks,
>
> Ranjith Pillai.
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>
>


--
Dean Wampler
http://www.aspectprogramming.com
http://www.newaspects.com