Reputation: 3211
I want to add logging into my Java application using AspectJ and Slf4j. Basically the aspect just delegeates to the slf4j methods in this fashion:
package my.domain.com;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public aspect MyAspectLogger {
private Logger logger;
public MyAspectLogger() {
this.logger = LoggerFactory.getLogger( "MyAspectLogger" );
}
pointcut callSomeFunction(): call(* de.my.domain.MyClass.*());
before() : callSomeFunction() {
logger.error( "**** (Before) Called something in MyClass ****" );
}
after() : callSomeFunction() {
System.out.println( "**** (After) Called something in MyClass ****" );
}
}
Why does the System.out.println()
print the message but the logger.error()
does not print the message?
Upvotes: 2
Views: 4822
Reputation: 311
You should make sure that there is a SLF4J implementation like logback on the classpath.
Upvotes: 2