kiltek
kiltek

Reputation: 3211

SLF4J logger does not print anything to console

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

Answers (1)

nille85
nille85

Reputation: 311

You should make sure that there is a SLF4J implementation like logback on the classpath.

Upvotes: 2

Related Questions