Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » AspectJ » how to catch debug joint points?
how to catch debug joint points? [message #48795] Fri, 25 February 2005 06:48 Go to next message
Eclipse UserFriend
Originally posted by: snpooo.gmail.com

I am planning to implement logging aspect with AspectJ, but i don't know
how to log debug info using AspecJ?


I can log debug info at any interested place in oop system.

For example:

public class ClassA {
...
public void MethodA(int a){
...
if(debugEnabled)
log.debug("debug info, a= "+ a);
}
}
...

}

In aop system, how can I get the same function as above?

If I add a String field member and assign it the debug info at where debug
info need to be logged, then i use apsect to catch this field write
joinpoint and log debug info.

e.g.

public class ClassA {
...
public void MethodA(int a){
...
String debugstring="debug info, a= "+ a;
}
}
...

}

is this method feasible? any other idea?
Thanks a lot!

Best regards
Re: how to catch debug joint points? [message #48885 is a reply to message #48795] Fri, 25 February 2005 16:05 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: adrian.redpointsoft.com

AOP is suited for concerns which are generalized and may apply
consistently to many different places. Debugging statements don't fit
well into this domain as they tend to be ad hoc and rely on the state of
the local variables which aren't exposed via AspectJ.

I notice that in your examples you seem to be just printing out the
arguments to methodA(). I don't think there is a good way to get all of
the arguments to all methods (even the new varargs support doesn't offer
this). The best that I can think of is to get the signature of all
methods, or to use the args() pointcut to expose the context of specific
methods.

> If I add a String field member and assign it the debug info at where
> debug info need to be logged, then i use apsect to catch this field
> write joinpoint and log debug info.
>
> e.g.
>
> public class ClassA {
> ...
> public void MethodA(int a){
> ...
> String debugstring="debug info, a= "+ a;
> }
> }
> ...

No, local variables are not exposed. If this were an instance variable,
you could do it but I'd recommend against it. I don't think this leads
to a maintainable system, nor does it help clarify the behavior of the
system. Making a call to "log.debug( debugstring )" is very clear and
by changing the log level, you can customize your output.

-adrian.
Re: how to catch debug joint points? [message #48975 is a reply to message #48885] Sat, 26 February 2005 02:44 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: snpooo.gmail.com

Thanks for your kind advice
Re: how to catch debug joint points? [message #51591 is a reply to message #48795] Sun, 15 May 2005 01:26 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: aronbock.hotmail.com

snpooo,

Despite what a prior respondent said, you may still be able to use AOP.
Look at it this way--you use debug statements to look at the state of your
app at some point in time. This state is arrived at by method calls [and
related computation]. Thus much of the time you could examine the state of
your app by looking at parameters to and return values from
methods--something for which AOP is very suited.

For example, if you have:

some method {
int a;
// some involved calculation with a
// ...

// now use a:
int b = a + ...
}

you could move the calculation for "a" out of the method, into its own
method, and locate it via pointcuts. Of course, this is a technique you
apply ad absurdum.

Regards,

--A



"snpooo" <snpooo@gmail.com> wrote in message
news:cvmho7$2v9$1@www.eclipse.org...
>I am planning to implement logging aspect with AspectJ, but i don't know
>how to log debug info using AspecJ?
>
>
> I can log debug info at any interested place in oop system.
> For example:
>
> public class ClassA {
> ...
> public void MethodA(int a){
> ...
> if(debugEnabled)
> log.debug("debug info, a= "+ a);
> }
> }
> ...
>
> }
>
> In aop system, how can I get the same function as above?
>
> If I add a String field member and assign it the debug info at where debug
> info need to be logged, then i use apsect to catch this field write
> joinpoint and log debug info.
>
> e.g.
>
> public class ClassA {
> ...
> public void MethodA(int a){
> ...
> String debugstring="debug info, a= "+ a;
> }
> }
> ...
>
> }
>
> is this method feasible? any other idea? Thanks a lot!
>
> Best regards
>
Re: how to catch debug joint points? [message #55484 is a reply to message #51591] Tue, 26 July 2005 08:20 Go to previous message
Eclipse UserFriend
Originally posted by: snpooo.gmail.com

aron bock,
Your idea may be useful sometimes, but if i need to refactor a large
system, it is terrible.
Anyway thanks

Best regards
Re: how to catch debug joint points? [message #587037 is a reply to message #48795] Fri, 25 February 2005 16:05 Go to previous message
Adrian Powell is currently offline Adrian PowellFriend
Messages: 16
Registered: July 2009
Junior Member
AOP is suited for concerns which are generalized and may apply
consistently to many different places. Debugging statements don't fit
well into this domain as they tend to be ad hoc and rely on the state of
the local variables which aren't exposed via AspectJ.

I notice that in your examples you seem to be just printing out the
arguments to methodA(). I don't think there is a good way to get all of
the arguments to all methods (even the new varargs support doesn't offer
this). The best that I can think of is to get the signature of all
methods, or to use the args() pointcut to expose the context of specific
methods.

> If I add a String field member and assign it the debug info at where
> debug info need to be logged, then i use apsect to catch this field
> write joinpoint and log debug info.
>
> e.g.
>
> public class ClassA {
> ...
> public void MethodA(int a){
> ...
> String debugstring="debug info, a= "+ a;
> }
> }
> ...

No, local variables are not exposed. If this were an instance variable,
you could do it but I'd recommend against it. I don't think this leads
to a maintainable system, nor does it help clarify the behavior of the
system. Making a call to "log.debug( debugstring )" is very clear and
by changing the log level, you can customize your output.

-adrian.
Re: how to catch debug joint points? [message #587059 is a reply to message #48885] Sat, 26 February 2005 02:44 Go to previous message
Eclipse UserFriend
Originally posted by: snpooo.gmail.com

Thanks for your kind advice
Re: how to catch debug joint points? [message #588091 is a reply to message #48795] Sun, 15 May 2005 01:26 Go to previous message
Eclipse UserFriend
Originally posted by: aronbock.hotmail.com

snpooo,

Despite what a prior respondent said, you may still be able to use AOP.
Look at it this way--you use debug statements to look at the state of your
app at some point in time. This state is arrived at by method calls [and
related computation]. Thus much of the time you could examine the state of
your app by looking at parameters to and return values from
methods--something for which AOP is very suited.

For example, if you have:

some method {
int a;
// some involved calculation with a
// ...

// now use a:
int b = a + ...
}

you could move the calculation for "a" out of the method, into its own
method, and locate it via pointcuts. Of course, this is a technique you
apply ad absurdum.

Regards,

--A



"snpooo" <snpooo@gmail.com> wrote in message
news:cvmho7$2v9$1@www.eclipse.org...
>I am planning to implement logging aspect with AspectJ, but i don't know
>how to log debug info using AspecJ?
>
>
> I can log debug info at any interested place in oop system.
> For example:
>
> public class ClassA {
> ...
> public void MethodA(int a){
> ...
> if(debugEnabled)
> log.debug("debug info, a= "+ a);
> }
> }
> ...
>
> }
>
> In aop system, how can I get the same function as above?
>
> If I add a String field member and assign it the debug info at where debug
> info need to be logged, then i use apsect to catch this field write
> joinpoint and log debug info.
>
> e.g.
>
> public class ClassA {
> ...
> public void MethodA(int a){
> ...
> String debugstring="debug info, a= "+ a;
> }
> }
> ...
>
> }
>
> is this method feasible? any other idea? Thanks a lot!
>
> Best regards
>
Re: how to catch debug joint points? [message #589621 is a reply to message #51591] Tue, 26 July 2005 08:20 Go to previous message
Eclipse UserFriend
Originally posted by: snpooo.gmail.com

aron bock,
Your idea may be useful sometimes, but if i need to refactor a large
system, it is terrible.
Anyway thanks

Best regards
Previous Topic:Information about AJDT release streams
Next Topic:Information about AJDT release streams
Goto Forum:
  


Current Time: Thu Dec 26 15:27:35 GMT 2024

Powered by FUDForum. Page generated in 0.04074 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top