Announcement Announcement Module
Collapse
No announcement yet.
commons logging, log4j and %l Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • commons logging, log4j and %l

    Hi,

    Using my LogAspect I'm faceing the problem that when I use commons logging with log4j and I want to log the location (%l flag), the location (fqcn + method name + line number) of the Aspect class and not of the proxied object is logged.

    How can I achive that the location of the proxied class is logged?

    Thx.

  • #2
    Not sure if I understand you correctly, but explore the API of org.aspectj.lang.JoinPoint to get the information about the join point that you need.

    -Ramnivas

    Comment


    • #3
      Code:
      Thread [main] (Suspended (breakpoint at line 22 in LogAspect))	
      	LogAspect.log(ProceedingJoinPoint) line: 22	
      	NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]	
      	NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39	
      	DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25	
      	Method.invoke(Object, Object...) line: 589	
      	AspectJAroundAdvice(AbstractAspectJAdvice).invokeAdviceMethodWithGivenArgs(Object[]) line: 562	
      	AspectJAroundAdvice(AbstractAspectJAdvice).invokeAdviceMethod(JoinPoint, JoinPointMatch, Object, Throwable) line: 551	
      	AspectJAroundAdvice.invoke(MethodInvocation) line: 56	
      	ReflectiveMethodInvocation.proceed() line: 176	
      	TransactionInterceptor.invoke(MethodInvocation) line: 107	
      	ReflectiveMethodInvocation.proceed() line: 176	
      	ExposeInvocationInterceptor.invoke(MethodInvocation) line: 89	
      	ReflectiveMethodInvocation.proceed() line: 176	
      	JdkDynamicAopProxy.invoke(Object, Method, Object[]) line: 210	
      	$Proxy18.doit(Foo) line: not available	
      	MyClass.doit(Foo) line: 39
      When I log the call in LogAspect.log the %l in log4j prints out LogAspect.log as caller of the logging call into log4j, since this class directly does the call.
      What I what is that it logs MyClass.doit.
      For this case log4j has a log method where i can supply the FQCN of the class which calls MyClass.doit. If I do so, log4j will print out MyClass.doit as caller aof the logging call.

      So my question is: How can I find out that $Proxy18 is the direct caller of MyClass?

      Comment


      • #4
        One way is to not use %l. Instead form your own message using line number and other information obtained from the join point object.

        -Ramnivas

        Comment


        • #5
          Of course. But then I will lose one of the really, really nice features of log4j
          So - there is no other way than creating an exception and stepping through the stacktrace to find out, that $Proxy18 is the caller?

          Comment


          • #6
            I believe there is a method on the joinpoint which gives you the real class name as well as the methods, parameters. If I'm not mistaken.

            Comment


            • #7
              Hm, well ProceedingJointPoint has a private field methodInvocation which itself has a protected field proxy. This is what I need, but it's not public...

              Comment

              Working...
              X