On 27 May 2011 15:07, Abhijit Inamdar <
Ainamdar@xxxxxxxxxxxxxx> wrote:
> I am trying to use AspectJ for tracing and I have hit the wall trying to figure out this problem. I have a prototype where my code works but it does not work with the "real" project. What I am trying to do is to prefix log statements with some additional information(class, line number etc).
> Here is the code:
> pointcut logCall() : call(* org.apache.log4j.Logger.*(..)) && !within(*..*Aspect);
>
> before() : logCall() {
> MDC.put(MDC_KEY, " (" + thisEnclosingJoinPointStaticPart.getSourceLocation()
> + ") " + thisEnclosingJoinPointStaticPart.getSignature().toShortString());
> }
>
> after() : logCall() {
> MDC.remove(MDC_KEY);
> }
>
> In the prototype this works fine giving the following output(for example):
> 2011-05-27 14:44:04,474 [main] WARN - (CommChannel.java:18) CommChannel.doComm(..) Delivering message by channel
>
> where "Delivering message by channel" is the original logged message and "(CommChannel.java:18) CommChannel.doComm(..)" was prefixed by the aspect code shown above.
>
> However when I move this to my "real" project this does nothing.
>
> Compiler output seems to indicate that it is finding the right join points. For example:
>
> [INFO] Join point 'method-call(org.apache.log4j.Logger org.apache.log4j.Logger.getLogger(java.lang.Class))' in Type 'com.mycompany.myapp.plugins.MyClass' (MyClass.java:55) advised by after advice from ''com.mycompany.myapp.aspects.tracing.MyAspect' (myaspects-2.0-SNAPSHOT.jar!MyAspect.class:65(from MyAspect.aj)) [with runtime test]
>
> However the original log statement is logged without my aspect prefix. Attaching a debugger to the process shows that it never enters the before or after advice. This means if I remove the MDC code and simply enter log statements into the before & after advice they are still never hit(i.e. the issue is NOT with MDC).
>
> I am running:
> Ubuntu 10.4 (Kernel Linux 2.6.32-31-generic)
> Tomcat 6.0.32
> Maven 2.2.1 with AspectJ dependencies
> <dependency>
> <groupId>org.aspectj</groupId>
> <artifactId>aspectjweaver</artifactId>
> <version>1.6.10</version>
> <scope>compile</scope>
> </dependency>
> <dependency>
> <groupId>org.aspectj</groupId>
> <artifactId>aspectjrt</artifactId>
> <version>1.6.10</version>
> </dependency>
>
> <plugin> ...
> <artifactId>aspectj-maven-plugin</artifactId>
> <version>1.3.1</version> ... etc
>
>
>
> PLEASE NOTE: I am able to get tracing to work in the "real" app. It just doesn't work with the above log4j pointcut.
>
> Sorry about the very long post but I am really out of ideas, so any pointers for further investigation will the great.
> _______________________________________________
> aspectj-users mailing list
>
aspectj-users@xxxxxxxxxxx
>
https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users