slf4j

All

Intro

I already talked about Log4J, but not about SLF4J. The Simple Logging Facade for Java is another way

SLF4J

 

Using SLF4J for the first time:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class HelloWorld {
  public static void main(String[] args) {
    Logger logger = LoggerFactory.getLogger(HelloWorld.class);
    logger.info("Hello World");
  }
}

migration

To migrate to SLF4J from log4J is quick simple since they have a migration tool, with some limitations though.

Tutorials

There are several tutorials on this matter.

 

 

Dependencies and underline logger framework

As the tutorial explains, if you use <sl4j-nop:175> you will basically only compile the project ~ getting rid of the sl4j issues.

But to actually use it, you must use logback-classic.jar and logback-core.jar, dependencies.

And in fact, you can stack sl4j above log4j, keeping the logger messages from both.

REFs

~ inline

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s