This is probably too academic but anyway here is how it goes. I have been trying to understand how logging works in OpenMRS. I notice that commons-logging dependency is explicitly excluded when declaring dependencies to external libraries in core for example, here, here and a dozen other places in the same POM file. I also noticed there is a dependency on slf4j and log4j. As I am going through the POM I get the impression that developers are supposed to use the SLF4J APIs for logging. However that does not seem to be the case. As far as I can remember I have only seen logging code using the Apache’s commons-logging API. I think most of the developers are familiar with this line of code below in the OpenMRS code base.
private final Log log = LogFactory.getLog(getClass());
LogFactory come from the commons library. Personally I have always used that same style. I have three questions.
- Why does commons-logging APIs work while it is excluded ? I even tried to do a
mvn dependency:resolve| grep commons-loggingbut it does not come up!
- How is logging intended/supposed to work?
- Why aren’t the developers using the SLF4J API? ( I am guilty too but I simply started using the style I found being used when I started working on OpenMRS projects).
Thanks in advance.