I am working on a JAVA project where all the logging in the code is done by using slf4j. e.g.
package my.project.package;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MyClass {
private Logger logger = LoggerFactory.getLogger(MyClass.class);
//some attributes, their getters and setters
public void initialize() {
//some code
logger.info("Data received successfully!");
//some code
}
}
Now, we also have a log4j2.xml file. This file is loaded when the servlet context is initialized by
Configurator.initialize(null, FileFinderUtil.findFile("log4j2.xml", projectName, fallback).getAbsolutePath());
where configurator is a class from log4j2 library. We also deploy this log4j2.xml file on the server(tomcat)
1) I have read this SO link about slf4j and log4j2 working together. If slf4j2 is an abstraction (i understand this as abstract class), how is it possible to initialize an object of this class? In java, abstract classes can not have objects
2) For the two working together, is it so that the slf4j object is writing the logs but is actually behind the scene using log4j2 library for it? Can some body explain this process in simple terms?