I am using Commons Logging over Log4J for logging. I have noticed that I get a logger by default (with out instantiating one). So in any class in Spring I can use logger.[level](). Commons Logging's documentation suggests that I get the log as a private class variable in every class such as:
I understand that this will retrieve the Log instance for the current class and if there is not an instance of a Log for the class it will be created. Also I understand that there is then a Log instance for every class that is run in my app.Code:public class Bob { private Log logger = LogFactory.getLog(this.getClass); ... }
My question is: If I use logger.[level]() without first getting the Log object from the LogFactory what happens? Do I have one instance of the Log class for the entire app? Do I get a new one every time the class is run? Does something else happen?
My next question is which is best practice? Explicitly get a Log class from the factory for each class in my app that needs to log or use use the logger provided?
Thanks in advance...


Reply With Quote
explain this please. of course SLF4J does not bind itself to a desired logging system a compilation time but at deployment time. not sure what you mean by compilation time binding but that would be very useless to have to re-compile app to switch logging system...
