According to be Spring Framework documentation, logging is the only mandatory dependency of Spring. It uses Apache Commons Logging by default, or can be configured to use SLF4J or Log4J instead. My question is for the application I am writing using Spring, instead of using a differnt logger class and instantiating a new logger object in my application, is it possible to get a reference to the logger Spring is using for itself?
According to be Spring Framework documentation, logging is the only mandatory dependency of Spring.
Share
Sure – loggers are only referenced by name. So if Spring uses “org.springframework.beans.abc” (for example) as a logger name, you can also ask for a logger of the same name. (Spring doesn’t log using just one logger / name – it uses several, depending upon what you’re using in Spring – as it should.)
However, I would strongly recommend against doing this. The cost of instantiating a new logger object should be minimal – and any savings in doing this would be more than offset by the additional confusion of doing so. Spring logs to Spring logger names. Your code should log to a logger name unique to your code. Otherwise, if something is logged, how do you know if it is coming from Spring code or your code? This would completely defeat the purpose of logger / category names.