LoggerFactory vs Logger

I have a question that I still could not find the answer to. So what is the difference between the two lines?

private static final Logger LOGGER = LoggerFactory.getLogger(MyClass.class);

and

private static final Logger LOGGER = Logger.getLogger(MyClass.class);

Which one should be used and why? Thank.

+4
source share
1 answer

You mentioned the question of how to and , m, assuming that your project is configured to use SLF4J and that he uses log4j binding.

If you use the SLF4J binding in your class (from the import org.slf4j.Logger;top), you need to use LoggerFactory.getLogger(and you will also need import org.slf4j.LoggerFactory;).

If you use log4j directly (from import org.apache.log4j.Logger;the top of your class), use Logger.getLogger.

SLF4J , , . , SLF4J, SLF4J. , log4j , , , , SLF4J. ( SLF4J, , .)

, , , , Logger, , , .

+3

All Articles