Member-only story
Migrating from One Logger to another using SLF4J.
In Previous article we talked about SLF4j where we saw how SLF4j helps us to maintain loose coupling between your app and logger. if you are using SLF4J with any other logger, it is quite easy to switch from one logger to another.
But in certain instances ,Old projects or framework , libraries which are not using SLF4J And having direct Logger implementation , it become difficult to migrate them to desired logger implementation. that’s where Bridging Library comes into picture.
Using Bridging Library we can migrate to desired logger slowly and gradually but can get the advantage of new logger implementation without changing much code.
Above diagram show how can we use various bridging library with slf4j and desired logger.
Let's take the example ,where in Application we have JCL , which is jakarta common logging library. and we want to migrate to logback gradually.
We have to do below changes.
Java , using jcl logger
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;
public class MyLooging {
public static void main(String args[]){
//Apache logger
Log jcl = LogFactory.getLog(MyLooging.class);
jcl.info("This is my apache logger");
}
}