Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Log4j DefaultCategoryFactory

Hi,


If you are going to weave into log4j classes, you are either going to
have to weave the jar before the app server starts and use your woven
jar or turn on loadtime weaving for the app server (using -javaagent).
 Though whether your aspect will be loaded early enough I'm not sure -
depending on the app server the Log4J classes may be loaded by a
different classloader than the one being used to load the app - and if
this happens the classloader that loads Log4J won't necessarily be
able to see your aspect and so won't know to apply it.

loadtime weaving is pretty simple: with the agent switched on the
classloaders get a weaver attached to them through which all bytecode
is passed that the classloader loads.  When initialized the weaver
searches the classpath of its associated loader for aop.xml files
which list the aspects it should be using.  Once initialized, anything
the classloader loads is passed through the weaver to have those
aspects applied.  So what you have to be aware of is that the weaver
attached to a classloader can only see aspects through the classpath
of that loader, it can't see aspects on the classpath of a
sub-classloader.

If you just wanted to catch the call side of the creation of the
loggers (that are occurring in the app), that is more straightforward
as you don't need to weave log4j, you just need to weave the app
itself, which you can do through compile time weaving or loadtime
weaving.

cheers,
Andy

On 29 August 2011 12:25, Chad Skinner <chadwskinner@xxxxxxxxx> wrote:
> I have been reading about Aspectj and am confused about how the weaving is
> setup. I was wondering if anyone knows if the following is possible and
> where/what documentation I should focus on reading to learn how it is done.
>
> Basically, I have written an aspect in a web application project that should
> notify me when a Log4j logger is created. Is it possible to use Aspectj in a
> web application without modifying the application server? I am not certain,
> from what I have read, if this is possible and what I need to do to get the
> aspect weaved into the Log4j DefaultCategoryFactory class after it has been
> loaded.
>
> Any help appreciated,
> -- Chad
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>


Back to the top