how to catch debug joint points? [message #48795] |
Fri, 25 February 2005 06:48 |
Eclipse User |
|
|
|
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 |
Eclipse User |
|
|
|
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 #51591 is a reply to message #48795] |
Sun, 15 May 2005 01:26 |
Eclipse User |
|
|
|
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 #588091 is a reply to message #48795] |
Sun, 15 May 2005 01:26 |
Eclipse User |
|
|
|
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
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.04074 seconds