I posted this on another forum and wanted to see if I can reach more people.
I am working on an application that consists of different Spring web apps.
Say we have:
- ComponentA.jar
- ComponentB.jar
And WAR files:
- Foo.war (contains ComponentA)
- Baa.war (contains ComponentA & ComponentB)
We are using Logback to log to our debug log. So say that the various classes of the application have the the following logger declaration:
private static final Log log = LoggerFactory.getLogger(NAME_OF_WAR_FILE + "." + NAME_OF_CONTAINING_COMPONENT + "." + PACKAGE.CLASS_NAME);
So example:
package a.b.c;
public class SomeClass {
private static final Log log = LoggerFactory.getLogger("Foo.war" + "." + "ComponentA" + "." + SomeClass.class);
}
package x.y.z;
public class SomeOtherClass {
private static final Log log = LoggerFactory.getLogger("Baa.war" + "." + "ComponentA" + "." + SomeOtherClass .class);
}
Assume that the name of the war file and component is set by a property and not hard-coded.
Is it possible to have an Aspect and Advice that can do something like the following (pseudo since I'm not sure it can be done):
@Aspect
public class TheAspect{
@Around("execution of a method")
public Object aroundSomething(ProceedingJoinPoint pjp){
Log log = get the log instance from the class that this advice is running on
if(log.isDebugEnabled())
// log something
Object o = pjp.proceed();
if(log.isDebugEnabled())
// log something else
return o;
}
}
The point here is to write to the log file using the log of the class instance which contains the method which is being intercepted by the Advice.
The application is presented as a single web app composed of Foo.war and Baa.war. Both Foo.war and Baa.war write to the same log file.
Example:
2011-09-22 14:35:35.159 MDT,DEBUG,Foo.war.ComponentA.a.b.c.SomeClass,Hello World Debug message
2011-09-22 14:35:35.159 MDT,DEBUG,Baa.war.ComponentA.a.b.c.SomeClass,Hello World Debug message
2011-09-22 14:35:35.159 MDT,DEBUG,Baa.war.ComponentB.x.y.z.SomeOtherClass,Hello World Debug message
Thanks in advance.