Using AspectJ log without Spring

I just worked on an old application that has a bad log or no logs. It does not implement the Spring framework.
Is it possible to implement AspectJ logging function without Spring?
If so, please offer me some useful lessons.

+7
source share
4 answers

try this link for a simple application showing using load time weaving without using Spring http://ganeshghag.blogspot.in/2012/10/demystifying-aop-getting-started-with.html

all that is needed is animated executables and jugs, as well as the META-INF \ aop.xml file containing the correct configuration.

also link to get details on using aspectj ltw without spring http://www.eclipse.org/aspectj/doc/next/devguide/ltw.html

+8
source

You can use aspectj without Spring (or log4j) to log messages in any aspect of the supported connection points,

For example,

public aspect ListAllMethodExecution { private int callDepth; private pointcut executionJoinPoints(): !within(ListAllMethodExecution) && execution (* *.*(..)); before(): executionJoinPoints(){ print("Before call " + thisJoinPoint); callDepth++; } after(): executionJoinPoints(){ callDepth--; print("After call " + thisJoinPoint); } private void print(String s){ for(int i=0; i<callDepth; i++) System.out.print(" "); System.out.println(s); } } 

You can modify the pointcut expression to register specific events or other static connection points that may interest you from specific packages. You can also change the printing method as you want to redirect logs.

You can use the download time or compile the time suitable for you. Hope this helps.

+4
source

Try loading time with spring .

Download Time (LTW) refers to the process of weaving AspectJ aspects into application class files as they are loaded into the Java Virtual Machine (JVM).

This means that you can add the logging aspect to classes also by providing security for objects outside the Spring IoC container.

+1
source

Perhaps this OpenSource can help you. https://code.google.com/p/perfspy/ . This is a log of performance monitoring and code verification. It uses ApsectJ to weave application code at runtime and records the execution time of each method and its input parameters and values. It has a user interface application in which you can view the method calls and their input and return values ​​in the form of trees. With it, you can identify performance bottlenecks and understand the complex flow of code.

0
source

All Articles